Some well known proxies respond with Content-Length=0, when returning 304. For robustness, always use the cached entity's content length, as modern browsers do.

This commit is contained in:
Raymond, Jayson 2019-02-06 07:21:09 -08:00
parent 1f06087fad
commit e6ca403d29
1 changed files with 3 additions and 4 deletions

View File

@ -145,10 +145,9 @@ class CachedHttpResponseGenerator {
if (transferEncodingIsPresent(response)) {
return;
}
final Header contentLength = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
if (contentLength == null) {
response.setHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.length));
}
// Some well known proxies respond with Content-Length=0, when returning 304. For robustness, always
// use the cached entity's content length, as modern browsers do.
response.setHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(body.length));
}
private boolean transferEncodingIsPresent(final HttpResponse response) {