Skip to content

Commit

Permalink
Allow null for ResponseEntity.HeadersBuilder::eTag
Browse files Browse the repository at this point in the history
Closes gh-28947
  • Loading branch information
poutsma committed Aug 16, 2022
1 parent ef178d2 commit 59c2f4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public interface HeadersBuilder<B extends HeadersBuilder<B>> {
* @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
Expand Down Expand Up @@ -562,12 +562,14 @@ public BodyBuilder contentType(MediaType contentType) {
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ void Etagheader() throws URISyntaxException {

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
Expand Down

0 comments on commit 59c2f4c

Please sign in to comment.