Efficiency improvements for #5977 (#5998)

Improve efficiency for non wrapped response for cache-contro
This commit is contained in:
Greg Wilkins 2021-02-23 12:56:22 +01:00 committed by GitHub
parent b836c2fda3
commit c0b0f80567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -181,7 +181,13 @@ public class ResourceService
public void setCacheControl(HttpField cacheControl) 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<String> getGzipEquivalentFileExtensions() public List<String> getGzipEquivalentFileExtensions()
@ -828,12 +834,12 @@ public class ResourceService
{ {
Response r = (Response)response; Response r = (Response)response;
r.putHeaders(content, contentLength, _etags); r.putHeaders(content, contentLength, _etags);
HttpFields f = r.getHttpFields(); HttpFields fields = r.getHttpFields();
if (_acceptRanges && !response.containsHeader(HttpHeader.ACCEPT_RANGES.asString())) if (_acceptRanges && !fields.contains(HttpHeader.ACCEPT_RANGES))
f.put(ACCEPT_RANGES); fields.put(ACCEPT_RANGES);
if (_cacheControl != null && !response.containsHeader(HttpHeader.CACHE_CONTROL.asString())) if (_cacheControl != null && !fields.contains(HttpHeader.CACHE_CONTROL))
f.put(_cacheControl); fields.put(_cacheControl);
} }
else else
{ {