File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed
main/java/org/springframework/web/reactive/function/server
test/java/org/springframework/web/reactive/function/server
main/java/org/springframework/web/servlet/function
test/java/org/springframework/web/servlet/function Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -371,6 +371,18 @@ interface Headers {
371
371
*/
372
372
List <String > header (String headerName );
373
373
374
+ /**
375
+ * Get the first header value, if any, for the header for the given name.
376
+ * <p>Returns {@code null} if no header values are found.
377
+ * @param headerName the header name
378
+ * @since 5.2.5
379
+ */
380
+ @ Nullable
381
+ default String firstHeader (String headerName ) {
382
+ List <String > list = header (headerName );
383
+ return list .isEmpty () ? null : list .get (0 );
384
+ }
385
+
374
386
/**
375
387
* Get the headers as an instance of {@link HttpHeaders}.
376
388
*/
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -208,6 +208,8 @@ public void header() {
208
208
assertThat (headers .acceptCharset ()).isEqualTo (acceptCharset );
209
209
assertThat (headers .contentLength ()).isEqualTo (OptionalLong .of (contentLength ));
210
210
assertThat (headers .contentType ()).isEqualTo (Optional .of (contentType ));
211
+ assertThat (headers .header (HttpHeaders .CONTENT_TYPE )).containsExactly (MediaType .TEXT_PLAIN_VALUE );
212
+ assertThat (headers .firstHeader (HttpHeaders .CONTENT_TYPE )).isEqualTo (MediaType .TEXT_PLAIN_VALUE );
211
213
assertThat (headers .asHttpHeaders ()).isEqualTo (httpHeaders );
212
214
}
213
215
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -307,6 +307,18 @@ interface Headers {
307
307
*/
308
308
List <String > header (String headerName );
309
309
310
+ /**
311
+ * Get the first header value, if any, for the header for the given name.
312
+ * <p>Returns {@code null} if no header values are found.
313
+ * @param headerName the header name
314
+ * @since 5.2.5
315
+ */
316
+ @ Nullable
317
+ default String firstHeader (String headerName ) {
318
+ List <String > list = header (headerName );
319
+ return list .isEmpty () ? null : list .get (0 );
320
+ }
321
+
310
322
/**
311
323
* Get the headers as an instance of {@link HttpHeaders}.
312
324
*/
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -209,6 +209,8 @@ public void header() {
209
209
assertThat (headers .acceptCharset ()).isEqualTo (acceptCharset );
210
210
assertThat (headers .contentLength ()).isEqualTo (OptionalLong .of (contentLength ));
211
211
assertThat (headers .contentType ()).isEqualTo (Optional .of (contentType ));
212
+ assertThat (headers .header (HttpHeaders .CONTENT_TYPE )).containsExactly (MediaType .TEXT_PLAIN_VALUE );
213
+ assertThat (headers .firstHeader (HttpHeaders .CONTENT_TYPE )).isEqualTo (MediaType .TEXT_PLAIN_VALUE );
212
214
assertThat (headers .asHttpHeaders ()).isEqualTo (httpHeaders );
213
215
}
214
216
You can’t perform that action at this time.
0 commit comments