From c0b0f805671f5d7ed3e750c609204024f202aaaa Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 23 Feb 2021 12:56:22 +0100 Subject: [PATCH] Efficiency improvements for #5977 (#5998) Improve efficiency for non wrapped response for cache-contro --- .../eclipse/jetty/server/ResourceService.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java index 4455d041dda..8ece91dc2f5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java @@ -181,7 +181,13 @@ public class ResourceService public void setCacheControl(HttpField cacheControl) { - _cacheControl = cacheControl; + if (cacheControl == null) + _cacheControl = null; + if (cacheControl.getHeader() != HttpHeader.CACHE_CONTROL) + throw new IllegalArgumentException("!Cache-Control"); + _cacheControl = cacheControl instanceof PreEncodedHttpField + ? cacheControl + : new PreEncodedHttpField(cacheControl.getHeader(), cacheControl.getValue()); } public List getGzipEquivalentFileExtensions() @@ -828,12 +834,12 @@ public class ResourceService { Response r = (Response)response; r.putHeaders(content, contentLength, _etags); - HttpFields f = r.getHttpFields(); - if (_acceptRanges && !response.containsHeader(HttpHeader.ACCEPT_RANGES.asString())) - f.put(ACCEPT_RANGES); + HttpFields fields = r.getHttpFields(); + if (_acceptRanges && !fields.contains(HttpHeader.ACCEPT_RANGES)) + fields.put(ACCEPT_RANGES); - if (_cacheControl != null && !response.containsHeader(HttpHeader.CACHE_CONTROL.asString())) - f.put(_cacheControl); + if (_cacheControl != null && !fields.contains(HttpHeader.CACHE_CONTROL)) + fields.put(_cacheControl); } else {