@@ -247,23 +247,25 @@ private boolean validateIfNoneMatch(@Nullable String etag) {
247
247
return true ;
248
248
}
249
249
250
- private boolean matchRequestedETags (Enumeration <String > requestedETags , @ Nullable String etag , boolean weakCompare ) {
251
- etag = padEtagIfNecessary (etag );
250
+ private boolean matchRequestedETags (Enumeration <String > requestedETags , @ Nullable String eTag , boolean weakCompare ) {
251
+ if (StringUtils .hasLength (eTag )) {
252
+ eTag = ETag .quoteETagIfNecessary (eTag );
253
+ }
252
254
while (requestedETags .hasMoreElements ()) {
253
255
// Compare weak/strong ETags as per https://datatracker.ietf.org/doc/html/rfc9110#section-8.8.3
254
256
for (ETag requestedETag : ETag .parse (requestedETags .nextElement ())) {
255
257
// only consider "lost updates" checks for unsafe HTTP methods
256
- if (requestedETag .isWildcard () && StringUtils .hasLength (etag )
258
+ if (requestedETag .isWildcard () && StringUtils .hasLength (eTag )
257
259
&& !SAFE_METHODS .contains (getRequest ().getMethod ())) {
258
260
return false ;
259
261
}
260
262
if (weakCompare ) {
261
- if (etagWeakMatch (etag , requestedETag .formattedTag ())) {
263
+ if (etagWeakMatch (eTag , requestedETag .formattedTag ())) {
262
264
return false ;
263
265
}
264
266
}
265
267
else {
266
- if (etagStrongMatch (etag , requestedETag .formattedTag ())) {
268
+ if (etagStrongMatch (eTag , requestedETag .formattedTag ())) {
267
269
return false ;
268
270
}
269
271
}
@@ -272,17 +274,6 @@ private boolean matchRequestedETags(Enumeration<String> requestedETags, @Nullabl
272
274
return true ;
273
275
}
274
276
275
- @ Nullable
276
- private String padEtagIfNecessary (@ Nullable String etag ) {
277
- if (!StringUtils .hasLength (etag )) {
278
- return etag ;
279
- }
280
- if ((etag .startsWith ("\" " ) || etag .startsWith ("W/\" " )) && etag .endsWith ("\" " )) {
281
- return etag ;
282
- }
283
- return "\" " + etag + "\" " ;
284
- }
285
-
286
277
private boolean etagStrongMatch (@ Nullable String first , @ Nullable String second ) {
287
278
if (!StringUtils .hasLength (first ) || first .startsWith ("W/" )) {
288
279
return false ;
@@ -346,13 +337,13 @@ private void updateResponseIdempotent(@Nullable String etag, long lastModifiedTi
346
337
}
347
338
}
348
339
349
- private void addCachingResponseHeaders (@ Nullable String etag , long lastModifiedTimestamp ) {
340
+ private void addCachingResponseHeaders (@ Nullable String eTag , long lastModifiedTimestamp ) {
350
341
if (getResponse () != null && SAFE_METHODS .contains (getRequest ().getMethod ())) {
351
342
if (lastModifiedTimestamp > 0 && parseDateValue (getResponse ().getHeader (HttpHeaders .LAST_MODIFIED )) == -1 ) {
352
343
getResponse ().setDateHeader (HttpHeaders .LAST_MODIFIED , lastModifiedTimestamp );
353
344
}
354
- if (StringUtils .hasLength (etag ) && getResponse ().getHeader (HttpHeaders .ETAG ) == null ) {
355
- getResponse ().setHeader (HttpHeaders .ETAG , padEtagIfNecessary ( etag ));
345
+ if (StringUtils .hasLength (eTag ) && getResponse ().getHeader (HttpHeaders .ETAG ) == null ) {
346
+ getResponse ().setHeader (HttpHeaders .ETAG , ETag . quoteETagIfNecessary ( eTag ));
356
347
}
357
348
}
358
349
}
0 commit comments