File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
main/java/org/springframework/http
test/java/org/springframework/http Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -404,7 +404,7 @@ public interface HeadersBuilder<B extends HeadersBuilder<B>> {
404
404
* @return this builder
405
405
* @see HttpHeaders#setETag(String)
406
406
*/
407
- B eTag (String etag );
407
+ B eTag (@ Nullable String etag );
408
408
409
409
/**
410
410
* Set the time the resource was last changed, as specified by the
@@ -562,12 +562,14 @@ public BodyBuilder contentType(MediaType contentType) {
562
562
}
563
563
564
564
@ Override
565
- public BodyBuilder eTag (String etag ) {
566
- if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
567
- etag = "\" " + etag ;
568
- }
569
- if (!etag .endsWith ("\" " )) {
570
- etag = etag + "\" " ;
565
+ public BodyBuilder eTag (@ Nullable String etag ) {
566
+ if (etag != null ) {
567
+ if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
568
+ etag = "\" " + etag ;
569
+ }
570
+ if (!etag .endsWith ("\" " )) {
571
+ etag = etag + "\" " ;
572
+ }
571
573
}
572
574
this .headers .setETag (etag );
573
575
return this ;
Original file line number Diff line number Diff line change @@ -207,6 +207,9 @@ void Etagheader() throws URISyntaxException {
207
207
208
208
responseEntity = ResponseEntity .ok ().eTag ("W/\" foo\" " ).build ();
209
209
assertThat (responseEntity .getHeaders ().getETag ()).isEqualTo ("W/\" foo\" " );
210
+
211
+ responseEntity = ResponseEntity .ok ().eTag (null ).build ();
212
+ assertThat (responseEntity .getHeaders ().getETag ()).isNull ();
210
213
}
211
214
212
215
@ Test
You can’t perform that action at this time.
0 commit comments