Refactor eTag formatting into utility method

See gh-33412
This commit is contained in:
hyunmin0317
2024-08-20 22:44:24 +09:00
committed by rstoyanchev
parent cc3f4b87ff
commit 80b264ba82
6 changed files with 18 additions and 57 deletions

View File

@@ -134,6 +134,15 @@ public record ETag(String tag, boolean weak) {
return result;
}
public static String format(String etag) {
if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
etag = "\"" + etag;
}
if (!etag.endsWith("\"")) {
etag = etag + "\"";
}
return etag;
}
private enum State {

View File

@@ -570,12 +570,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
@Override
public BodyBuilder eTag(@Nullable String etag) {
if (etag != null) {
if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
etag = "\"" + etag;
}
if (!etag.endsWith("\"")) {
etag = etag + "\"";
}
etag = ETag.format(etag);
}
this.headers.setETag(etag);
return this;