Repository navigation
Expand file tree
/
Copy pathNativeRequest.java
More file actions
157 lines (139 loc) · 4.47 KB
/
Copy pathNativeRequest.java
File metadata and controls
157 lines (139 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jooby.spi;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Executor;
import org.jooby.Cookie;
/**
* Minimal/basic implementation of HTTP request. A server implementor must provide an implementation
* of {@link NativeRequest}.
*
* @author edgar
* @since 0.5.0
*/
public interface NativeRequest {
/**
* @return The name of the HTTP method with which this request was made, for example, GET, POST,
* or PUT.
*/
String method();
/**
* @return The part of this request's URL from the protocol
* name up to the query string in the first line of the HTTP request
*/
String path();
/**
* @return List with all the parameter names from query string plus any other form/multipart param
* names (excluding file uploads). This method should NOT returns null, absence of params
* is represented by an empty list.
* @throws Exception If param extraction fails.
*/
List<String> paramNames() throws Exception;
/**
* Get all the params for the provided name or a empty list.
*
* @param name Parameter name.
* @return Get all the params for the provided name or a empty list.
* @throws Exception If param parsing fails.
*/
List<String> params(String name) throws Exception;
/**
* Get all the headers for the provided name or a empty list.
*
* @param name Header name.
* @return Get all the headers for the provided name or a empty list.
*/
List<String> headers(String name);
/**
* Get the first header for the provided name or a empty list.
*
* @param name Header name.
* @return The first header for the provided name or a empty list.
*/
Optional<String> header(final String name);
/**
* @return All the header names or an empty list.
*/
List<String> headerNames();
/**
* @return All the cookies or an empty list.
*/
List<Cookie> cookies();
/**
* Get all the files for the provided name or an empty list.
*
* @param name File name.
* @return All the files or an empty list.
* @throws IOException If file parsing fails.
*/
List<NativeUpload> files(String name) throws IOException;
/**
* Input stream that represent the body.
*
* @return Body as an input stream.
* @throws IOException If body read fails.
*/
InputStream in() throws IOException;
/**
* @return The IP address of the client or last proxy that sent the request.
*/
String ip();
/**
* @return The name and version of the protocol the request uses in the form
* <i>protocol/majorVersion.minorVersion</i>, for example, HTTP/1.1
*/
String protocol();
/**
* @return True if this request was made using a secure channel, such as HTTPS.
*/
boolean secure();
/**
* Upgrade the request to something else...like a web socket.
*
* @param type Upgrade type.
* @param <T> Upgrade type.
* @return A instance of the upgrade.
* @throws Exception If the upgrade fails or it is un-supported.
* @see NativeWebSocket
*/
<T> T upgrade(Class<T> type) throws Exception;
/**
* Put the request in async mode.
*
* @param executor Executor to use.
* @param runnable Task to run.
*/
void startAsync(Executor executor, Runnable runnable);
/**
* Send push promise to the client.
*
* @param method HTTP method.
* @param path HTTP path.
* @param headers HTTP headers.
* @throws Exception If something goes wrong.
*/
default void push(final String method, final String path, final Map<String, Object> headers)
throws Exception {
upgrade(NativePushPromise.class).push(method, path, headers);
}
}