HTTPCLIENT-1690: Avoid updating the cache entry with Content-Encoding headers too. (missing piece from last commit). Updated the test case

This commit is contained in:
Sudheera Palihakkara 2018-01-15 18:08:58 +08:00 committed by Oleg Kalnichevski
parent 0bc7f67178
commit 5f2ad23ab3
2 changed files with 14 additions and 0 deletions

View File

@ -163,6 +163,10 @@ class CacheUpdateHandler {
}
for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
final Header responseHeader = it.next();
// Since we do not expect a content in a 304 response, should update the cache entry with Content-Encoding
if (HttpHeaders.CONTENT_ENCODING.equals(responseHeader.getName())) {
continue;
}
headerGroup.addHeader(responseHeader);
}
return headerGroup.getAllHeaders();

View File

@ -263,6 +263,7 @@ public class TestCacheUpdateHandler {
final Header[] updatedHeaders = updatedEntry.getAllHeaders();
headersContain(updatedHeaders, "Content-Encoding", "identity");
headersNotContain(updatedHeaders, "Content-Encoding", "gzip");
}
private void headersContain(final Header[] headers, final String name, final String value) {
@ -276,4 +277,13 @@ public class TestCacheUpdateHandler {
fail("Header [" + name + ": " + value + "] not found in headers.");
}
private void headersNotContain(final Header[] headers, final String name, final String value) {
for (final Header header : headers) {
if (header.getName().equals(name)) {
if (header.getValue().equals(value)) {
fail("Header [" + name + ": " + value + "] found in headers where it should not be");
}
}
}
}
}