|
34 | 34 | */ |
35 | 35 | public interface NativeRequest { |
36 | 36 | /** |
37 | | - * @return Http method. |
| 37 | + * @return The name of the HTTP method with which this request was made, for example, GET, POST, |
| 38 | + * or PUT. |
38 | 39 | */ |
39 | 40 | String method(); |
40 | 41 |
|
| 42 | + /** |
| 43 | + * @return The part of this request's URL from the protocol |
| 44 | + * name up to the query string in the first line of the HTTP request |
| 45 | + */ |
41 | 46 | String path(); |
42 | 47 |
|
| 48 | + /** |
| 49 | + * @return List with all the parameter names from query string plus any other form/multipart param |
| 50 | + * names (excluding file uploads). This method should NOT returns null, absence of params |
| 51 | + * is represented by an empty list. |
| 52 | + * @throws Exception If param extraction fails. |
| 53 | + */ |
43 | 54 | List<String> paramNames() throws Exception; |
44 | 55 |
|
| 56 | + /** |
| 57 | + * Get all the params for the provided name or a empty list. |
| 58 | + * |
| 59 | + * @param name Parameter name. |
| 60 | + * @return Get all the params for the provided name or a empty list. |
| 61 | + * @throws Exception If param parsing fails. |
| 62 | + */ |
45 | 63 | List<String> params(String name) throws Exception; |
46 | 64 |
|
| 65 | + /** |
| 66 | + * Get all the headers for the provided name or a empty list. |
| 67 | + * |
| 68 | + * @param name Header name. |
| 69 | + * @return Get all the headers for the provided name or a empty list. |
| 70 | + */ |
47 | 71 | List<String> headers(String name); |
48 | 72 |
|
49 | | - Optional<String> header(String name); |
| 73 | + /** |
| 74 | + * Get the first header for the provided name or a empty list. |
| 75 | + * |
| 76 | + * @param name Header name. |
| 77 | + * @return The first header for the provided name or a empty list. |
| 78 | + */ |
| 79 | + default Optional<String> header(final String name) { |
| 80 | + List<String> headers = headers(name); |
| 81 | + return headers.size() == 0 ? Optional.empty() : Optional.of(headers.get(0)); |
| 82 | + } |
50 | 83 |
|
| 84 | + /** |
| 85 | + * @return All the header names or an empty list. |
| 86 | + */ |
51 | 87 | List<String> headerNames(); |
52 | 88 |
|
| 89 | + /** |
| 90 | + * @return All the cookies or an empty list. |
| 91 | + */ |
53 | 92 | List<Cookie> cookies(); |
54 | 93 |
|
| 94 | + /** |
| 95 | + * Get all the files for the provided name or an empty list. |
| 96 | + * |
| 97 | + * @param name File name. |
| 98 | + * @return All the files or an empty list. |
| 99 | + * @throws IOException If file parsing fails. |
| 100 | + */ |
55 | 101 | List<NativeUpload> files(String name) throws IOException; |
56 | 102 |
|
| 103 | + /** |
| 104 | + * Input stream that represent the body. |
| 105 | + * |
| 106 | + * @return Body as an input stream. |
| 107 | + * @throws IOException If body read fails. |
| 108 | + */ |
57 | 109 | InputStream in() throws IOException; |
58 | 110 |
|
| 111 | + /** |
| 112 | + * @return The IP address of the client or last proxy that sent the request. |
| 113 | + */ |
59 | 114 | String ip(); |
60 | 115 |
|
| 116 | + /** |
| 117 | + * The fully qualified name of the client or the last proxy that sent the request. |
| 118 | + * If the engine cannot or chooses not to resolve the hostname (to improve performance), |
| 119 | + * this method returns the dotted-string form of the IP address |
| 120 | + * |
| 121 | + * @return The fully qualified name of the client or the last proxy that sent the request. |
| 122 | + */ |
61 | 123 | String hostname(); |
62 | 124 |
|
| 125 | + /** |
| 126 | + * @return The name and version of the protocol the request uses in the form |
| 127 | + * <i>protocol/majorVersion.minorVersion</i>, for example, HTTP/1.1 |
| 128 | + */ |
63 | 129 | String protocol(); |
64 | 130 |
|
| 131 | + /** |
| 132 | + * @return True if this request was made using a secure channel, such as HTTPS. |
| 133 | + */ |
65 | 134 | boolean secure(); |
66 | 135 |
|
| 136 | + /** |
| 137 | + * Upgrade the request to something else...like a web socket. |
| 138 | + * |
| 139 | + * @param type Upgrade type. |
| 140 | + * @return A instance of the upgrade. |
| 141 | + * @throws Exception If the upgrade fails or it is un-supported. |
| 142 | + * @see NativeWebSocket |
| 143 | + */ |
67 | 144 | <T> T upgrade(Class<T> type) throws Exception; |
68 | 145 |
|
69 | 146 | } |
0 commit comments