Quote ETags set with ResponseEntity builder API

Prior to this change, trying to set an unquoted ETag with
`ResponseEntity`'s API would throw an `IllegalArgumentException`.

This commit automatically quotes ETag values set using ResponseEntity.

Issue: SPR-13378
This commit is contained in:
Brian Clozel
2015-08-22 15:29:19 +02:00
parent 2df3646e90
commit 88405be8a5
2 changed files with 21 additions and 3 deletions

View File

@@ -134,14 +134,12 @@ public class ResponseEntityTests {
@Test
public void headers() throws URISyntaxException {
String eTag = "\"foo\"";
URI location = new URI("location");
long contentLength = 67890;
MediaType contentType = MediaType.TEXT_PLAIN;
ResponseEntity<Void> responseEntity = ResponseEntity.ok().
allow(HttpMethod.GET).
eTag(eTag).
lastModified(12345L).
location(location).
contentLength(contentLength).
@@ -153,7 +151,6 @@ public class ResponseEntityTests {
HttpHeaders responseHeaders = responseEntity.getHeaders();
assertEquals("GET", responseHeaders.getFirst("Allow"));
assertEquals(eTag, responseHeaders.getFirst("ETag"));
assertEquals("Thu, 01 Jan 1970 00:00:12 GMT",
responseHeaders.getFirst("Last-Modified"));
assertEquals(location.toASCIIString(),
@@ -164,6 +161,19 @@ public class ResponseEntityTests {
assertNull(responseEntity.getBody());
}
@Test
public void Etagheader() throws URISyntaxException {
ResponseEntity<Void> responseEntity = ResponseEntity.ok().eTag("\"foo\"").build();
assertEquals("\"foo\"", responseEntity.getHeaders().getETag());
responseEntity = ResponseEntity.ok().eTag("foo").build();
assertEquals("\"foo\"", responseEntity.getHeaders().getETag());
responseEntity = ResponseEntity.ok().eTag("W/\"foo\"").build();
assertEquals("W/\"foo\"", responseEntity.getHeaders().getETag());
}
@Test
public void headersCopy() {
HttpHeaders customHeaders = new HttpHeaders();