Allow null for ResponseEntity.HeadersBuilder::eTag
Closes gh-28947
This commit is contained in:
parent
ef178d24ec
commit
59c2f4c069
|
|
@ -404,7 +404,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
|||
* @return this builder
|
||||
* @see HttpHeaders#setETag(String)
|
||||
*/
|
||||
B eTag(String etag);
|
||||
B eTag(@Nullable String etag);
|
||||
|
||||
/**
|
||||
* Set the time the resource was last changed, as specified by the
|
||||
|
|
@ -562,12 +562,14 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BodyBuilder eTag(String etag) {
|
||||
if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
|
||||
etag = "\"" + etag;
|
||||
}
|
||||
if (!etag.endsWith("\"")) {
|
||||
etag = etag + "\"";
|
||||
public BodyBuilder eTag(@Nullable String etag) {
|
||||
if (etag != null) {
|
||||
if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
|
||||
etag = "\"" + etag;
|
||||
}
|
||||
if (!etag.endsWith("\"")) {
|
||||
etag = etag + "\"";
|
||||
}
|
||||
}
|
||||
this.headers.setETag(etag);
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -207,6 +207,9 @@ class ResponseEntityTests {
|
|||
|
||||
responseEntity = ResponseEntity.ok().eTag("W/\"foo\"").build();
|
||||
assertThat(responseEntity.getHeaders().getETag()).isEqualTo("W/\"foo\"");
|
||||
|
||||
responseEntity = ResponseEntity.ok().eTag(null).build();
|
||||
assertThat(responseEntity.getHeaders().getETag()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue