Add ServerRequest::firstHeader

This commit introduces the method firstHeaderiin both WebMvc.fn and
WebFlux.fn, which return the first header value of a given header name,
if any.
This commit is contained in:
Arjen Poutsma
2020-03-10 12:06:11 +01:00
parent b92515bdee
commit fc12891006
4 changed files with 32 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -209,6 +209,8 @@ public class DefaultServerRequestTests {
assertThat(headers.acceptCharset()).isEqualTo(acceptCharset);
assertThat(headers.contentLength()).isEqualTo(OptionalLong.of(contentLength));
assertThat(headers.contentType()).isEqualTo(Optional.of(contentType));
assertThat(headers.header(HttpHeaders.CONTENT_TYPE)).containsExactly(MediaType.TEXT_PLAIN_VALUE);
assertThat(headers.firstHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.TEXT_PLAIN_VALUE);
assertThat(headers.asHttpHeaders()).isEqualTo(httpHeaders);
}