50
50
51
51
/**
52
52
* Represents a server-side HTTP request, as handled by a {@code HandlerFunction}.
53
- * Access to headers and body is offered by {@link Headers} and
53
+ *
54
+ * <p>Access to headers and body is offered by {@link Headers} and
54
55
* {@link #body(BodyExtractor)}, respectively.
55
56
*
56
57
* @author Arjen Poutsma
60
61
public interface ServerRequest {
61
62
62
63
/**
63
- * Return the HTTP method.
64
+ * Get the HTTP method.
64
65
* @return the HTTP method as an HttpMethod enum value, or {@code null}
65
66
* if not resolvable (e.g. in case of a non-standard HTTP method)
66
67
*/
@@ -70,18 +71,18 @@ default HttpMethod method() {
70
71
}
71
72
72
73
/**
73
- * Return the name of the HTTP method.
74
+ * Get the name of the HTTP method.
74
75
* @return the HTTP method as a String
75
76
*/
76
77
String methodName ();
77
78
78
79
/**
79
- * Return the request URI.
80
+ * Get the request URI.
80
81
*/
81
82
URI uri ();
82
83
83
84
/**
84
- * Return a {@code UriBuilderComponents} from the URI associated with this
85
+ * Get a {@code UriBuilderComponents} from the URI associated with this
85
86
* {@code ServerRequest}, while also overlaying with values from the headers
86
87
* "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>),
87
88
* or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
@@ -91,26 +92,26 @@ default HttpMethod method() {
91
92
UriBuilder uriBuilder ();
92
93
93
94
/**
94
- * Return the request path.
95
+ * Get the request path.
95
96
*/
96
97
default String path () {
97
98
return uri ().getRawPath ();
98
99
}
99
100
100
101
/**
101
- * Return the request path as {@code PathContainer}.
102
+ * Get the request path as a {@code PathContainer}.
102
103
*/
103
104
default PathContainer pathContainer () {
104
105
return PathContainer .parsePath (path ());
105
106
}
106
107
107
108
/**
108
- * Return the headers of this request.
109
+ * Get the headers of this request.
109
110
*/
110
111
Headers headers ();
111
112
112
113
/**
113
- * Return the cookies of this request.
114
+ * Get the cookies of this request.
114
115
*/
115
116
MultiValueMap <String , HttpCookie > cookies ();
116
117
@@ -166,28 +167,22 @@ default PathContainer pathContainer() {
166
167
<T > Flux <T > bodyToFlux (ParameterizedTypeReference <T > typeReference );
167
168
168
169
/**
169
- * Return the request attribute value if present.
170
+ * Get the request attribute value if present.
170
171
* @param name the attribute name
171
172
* @return the attribute value
172
173
*/
173
174
default Optional <Object > attribute (String name ) {
174
- Map <String , Object > attributes = attributes ();
175
- if (attributes .containsKey (name )) {
176
- return Optional .of (attributes .get (name ));
177
- }
178
- else {
179
- return Optional .empty ();
180
- }
175
+ return Optional .ofNullable (attributes ().get (name ));
181
176
}
182
177
183
178
/**
184
- * Return a mutable map of request attributes.
179
+ * Get a mutable map of request attributes.
185
180
* @return the request attributes
186
181
*/
187
182
Map <String , Object > attributes ();
188
183
189
184
/**
190
- * Return the first query parameter with the given name, if present.
185
+ * Get the first query parameter with the given name, if present.
191
186
* @param name the parameter name
192
187
* @return the parameter value
193
188
*/
@@ -206,12 +201,12 @@ default Optional<String> queryParam(String name) {
206
201
}
207
202
208
203
/**
209
- * Return all query parameters for this request.
204
+ * Get all query parameters for this request.
210
205
*/
211
206
MultiValueMap <String , String > queryParams ();
212
207
213
208
/**
214
- * Return the path variable with the given name, if present.
209
+ * Get the path variable with the given name, if present.
215
210
* @param name the variable name
216
211
* @return the variable value
217
212
* @throws IllegalArgumentException if there is no path variable with the given name
@@ -227,38 +222,38 @@ default String pathVariable(String name) {
227
222
}
228
223
229
224
/**
230
- * Return all path variables for this request.
225
+ * Get all path variables for this request.
231
226
*/
232
227
Map <String , String > pathVariables ();
233
228
234
229
/**
235
- * Return the web session for this request. Always guaranteed to
236
- * return an instance either matching to the session id requested by the
237
- * client, or with a new session id either because the client did not
238
- * specify one or because the underlying session had expired. Use of this
239
- * method does not automatically create a session.
230
+ * Get the web session for this request.
231
+ * <p>Always guaranteed to return an instance either matching the session id
232
+ * requested by the client, or with a new session id either because the client
233
+ * did not specify one or because the underlying session had expired.
234
+ * <p>Use of this method does not automatically create a session.
240
235
*/
241
236
Mono <WebSession > session ();
242
237
243
238
/**
244
- * Return the authenticated user for the request, if any.
239
+ * Get the authenticated user for the request, if any.
245
240
*/
246
241
Mono <? extends Principal > principal ();
247
242
248
243
/**
249
- * Return the form data from the body of the request if the Content-Type is
244
+ * Get the form data from the body of the request if the Content-Type is
250
245
* {@code "application/x-www-form-urlencoded"} or an empty map otherwise.
251
246
* <p><strong>Note:</strong> calling this method causes the request body to
252
- * be read and parsed in full and the resulting {@code MultiValueMap} is
247
+ * be read and parsed in full, and the resulting {@code MultiValueMap} is
253
248
* cached so that this method is safe to call more than once.
254
249
*/
255
250
Mono <MultiValueMap <String , String >> formData ();
256
251
257
252
/**
258
- * Return the parts of a multipart request if the Content-Type is
253
+ * Get the parts of a multipart request if the Content-Type is
259
254
* {@code "multipart/form-data"} or an empty map otherwise.
260
255
* <p><strong>Note:</strong> calling this method causes the request body to
261
- * be read and parsed in full and the resulting {@code MultiValueMap} is
256
+ * be read and parsed in full, and the resulting {@code MultiValueMap} is
262
257
* cached so that this method is safe to call more than once.
263
258
*/
264
259
Mono <MultiValueMap <String , Part >> multipartData ();
@@ -285,59 +280,60 @@ static ServerRequest create(ServerWebExchange exchange, List<HttpMessageReader<?
285
280
interface Headers {
286
281
287
282
/**
288
- * Return the list of acceptable {@code MediaType media types},
289
- * as specified by the {@code Accept} header.
290
- * <p>Returns an empty list when the acceptable media types are unspecified.
283
+ * Get the list of acceptable media types, as specified by the {@code Accept}
284
+ * header.
285
+ * <p>Returns an empty list if the acceptable media types are unspecified.
291
286
*/
292
287
List <MediaType > accept ();
293
288
294
289
/**
295
- * Return the list of acceptable {@code Charset charsets},
296
- * as specified by the {@code Accept-Charset} header.
290
+ * Get the list of acceptable charsets, as specified by the
291
+ * {@code Accept-Charset} header.
297
292
*/
298
293
List <Charset > acceptCharset ();
299
294
300
295
/**
301
- * Return the list of acceptable {@code Locale.LanguageRange languages},
302
- * as specified by the {@code Accept-Language} header.
296
+ * Get the list of acceptable languages, as specified by the
297
+ * {@code Accept-Language} header.
303
298
*/
304
299
List <Locale .LanguageRange > acceptLanguage ();
305
300
306
301
/**
307
- * Return the length of the body in bytes, as specified by the
302
+ * Get the length of the body in bytes, as specified by the
308
303
* {@code Content-Length} header.
309
304
*/
310
305
OptionalLong contentLength ();
311
306
312
307
/**
313
- * Return the {@code MediaType media type} of the body, as specified
314
- * by the {@code Content-Type} header.
308
+ * Get the media type of the body, as specified by the
309
+ * {@code Content-Type} header.
315
310
*/
316
311
Optional <MediaType > contentType ();
317
312
318
313
/**
319
- * Return the value of the required {@code Host} header.
320
- * <p>If the header value does not contain a port, the returned
321
- * {@linkplain InetSocketAddress#getPort() port} will be {@code 0}.
314
+ * Get the value of the {@code Host} header, if available.
315
+ * <p>If the header value does not contain a port, the
316
+ * {@linkplain InetSocketAddress#getPort() port} in the returned address will
317
+ * be {@code 0}.
322
318
*/
323
319
@ Nullable
324
320
InetSocketAddress host ();
325
321
326
322
/**
327
- * Return the value of the {@code Range} header.
323
+ * Get the value of the {@code Range} header.
328
324
* <p>Returns an empty list when the range is unknown.
329
325
*/
330
326
List <HttpRange > range ();
331
327
332
328
/**
333
- * Return the header value(s), if any, for the header of the given name.
334
- * <p>Return an empty list if no header values are found.
329
+ * Get the header value(s), if any, for the header of the given name.
330
+ * <p>Returns an empty list if no header values are found.
335
331
* @param headerName the header name
336
332
*/
337
333
List <String > header (String headerName );
338
334
339
335
/**
340
- * Return the headers as a {@link HttpHeaders} instance .
336
+ * Get the headers as an instance of {@link HttpHeaders}.
341
337
*/
342
338
HttpHeaders asHttpHeaders ();
343
339
}
0 commit comments