HTTPCLIENT-2277: Removal of support for deprecated `Pragma` header

This commit is contained in:
Oleg Kalnichevski 2023-07-16 14:40:55 +02:00
parent d1d6eec7dd
commit a19adcb0dd
6 changed files with 4 additions and 94 deletions

View File

@ -26,7 +26,6 @@
*/
package org.apache.hc.client5.http.impl.cache;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.Method;
@ -64,11 +63,6 @@ class CacheableRequestPolicy {
return false;
}
if (request.countHeaders(HttpHeaders.PRAGMA) > 0) {
LOG.debug("request with Pragma header is not serveable from cache");
return false;
}
if (cacheControl.isNoStore()) {
LOG.debug("Request with no-store is not serveable from cache");
return false;

View File

@ -103,7 +103,6 @@ class ConditionalRequestBuilder<T extends HttpRequest> {
public T buildUnconditionalRequest(final T request) {
final T newRequest = messageCopier.create(request);
newRequest.addHeader(HttpHeaders.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE);
newRequest.addHeader(HttpHeaders.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE);
newRequest.removeHeaders(HttpHeaders.IF_RANGE);
newRequest.removeHeaders(HttpHeaders.IF_MATCH);
newRequest.removeHeaders(HttpHeaders.IF_NONE_MATCH);

View File

@ -65,22 +65,6 @@ public class TestCacheableRequestPolicy {
Assertions.assertFalse(policy.isServableFromCache(cacheControl2, request));
}
@Test
public void testIsGetWithPragmaServableFromCache() {
final BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
request.addHeader("Pragma", "no-cache");
final RequestCacheControl cacheControl = RequestCacheControl.builder()
.build();
Assertions.assertFalse(policy.isServableFromCache(cacheControl, request));
final BasicHttpRequest request2 = new BasicHttpRequest("GET", "someUri");
request2.addHeader("Pragma", "value1");
request2.addHeader("Pragma", "value2");
Assertions.assertFalse(policy.isServableFromCache(cacheControl, request2));
}
@Test
public void testIsHeadServableFromCache() {
final BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
@ -114,24 +98,6 @@ public class TestCacheableRequestPolicy {
Assertions.assertFalse(policy.isServableFromCache(cacheControl2, request));
}
@Test
public void testIsHeadWithPragmaServableFromCache() {
final BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
final RequestCacheControl cacheControl = RequestCacheControl.builder()
.setNoCache(true)
.build();
Assertions.assertFalse(policy.isServableFromCache(cacheControl, request));
final BasicHttpRequest request2 = new BasicHttpRequest("HEAD", "someUri");
request2.addHeader("Pragma", "value1");
request2.addHeader("Pragma", "value2");
final RequestCacheControl cacheControl2 = RequestCacheControl.builder()
.build();
Assertions.assertFalse(policy.isServableFromCache(cacheControl2, request2));
}
@Test
public void testIsArbitraryMethodServableFromCache() {
final BasicHttpRequest request = new BasicHttpRequest("TRACE", "someUri");

View File

@ -29,18 +29,15 @@ package org.apache.hc.client5.http.impl.cache;
import java.time.Instant;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.http.message.BasicHttpRequest;
import org.apache.hc.core5.http.message.MessageSupport;
import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@ -211,21 +208,6 @@ public class TestConditionalRequestBuilder {
Assertions.assertTrue(requestCacheControl.isNoCache());
}
@Test
public void testBuildUnconditionalRequestAddsPragmaNoCache()
throws Exception {
final HttpRequest result = impl.buildUnconditionalRequest(request);
boolean ccNoCacheFound = false;
final Iterator<HeaderElement> it = MessageSupport.iterate(result, HttpHeaders.PRAGMA);
while (it.hasNext()) {
final HeaderElement elt = it.next();
if ("no-cache".equals(elt.getName())) {
ccNoCacheFound = true;
}
}
Assertions.assertTrue(ccNoCacheFound);
}
@Test
public void testBuildUnconditionalRequestDoesNotUseIfRange()
throws Exception {

View File

@ -453,13 +453,6 @@ public class TestProtocolRecommendations {
testDoesNotReturnStaleResponseOnError(req);
}
@Test
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFirstHandOneWithPragma() throws Exception {
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
req.setHeader("Pragma","no-cache");
testDoesNotReturnStaleResponseOnError(req);
}
@Test
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxAge() throws Exception {
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");

View File

@ -397,13 +397,6 @@ public class TestProtocolRequirements {
testOrderOfMultipleHeadersIsPreservedOnRequests("Expect", post);
}
@Test
public void testOrderOfMultiplePragmaHeadersIsPreservedOnRequests() throws Exception {
request.addHeader("Pragma", "no-cache");
request.addHeader("Pragma", "x-pragma-1, x-pragma-2");
testOrderOfMultipleHeadersIsPreservedOnRequests("Pragma", request);
}
@Test
public void testOrderOfMultipleViaHeadersIsPreservedOnRequests() throws Exception {
request.addHeader(HttpHeaders.VIA, "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
@ -451,13 +444,6 @@ public class TestProtocolRequirements {
testOrderOfMultipleHeadersIsPreservedOnResponses("Content-Language");
}
@Test
public void testOrderOfMultiplePragmaHeadersIsPreservedOnResponses() throws Exception {
originResponse.addHeader("Pragma", "no-cache, x-pragma-2");
originResponse.addHeader("Pragma", "x-pragma-1");
testOrderOfMultipleHeadersIsPreservedOnResponses("Pragma");
}
@Test
public void testOrderOfMultipleViaHeadersIsPreservedOnResponses() throws Exception {
originResponse.addHeader(HttpHeaders.VIA, "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
@ -2765,7 +2751,6 @@ public class TestProtocolRequirements {
r.setHeader("Expires", DateUtils.formatStandardDate(Instant.now().plusSeconds(10)));
r.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now().minusSeconds(10)));
r.setHeader("Location", "http://foo.example.com/other2");
r.setHeader("Pragma", "x-pragma");
r.setHeader("Retry-After","180");
}
@ -2794,7 +2779,7 @@ public class TestProtocolRequirements {
"Cache-Control", "ETag", "Allow", "Content-Encoding",
"Content-Language", "Content-Length", "Content-Location",
"Content-MD5", "Content-Type", "Expires", "Last-Modified",
"Location", "Pragma", "Retry-After"
"Location", "Retry-After"
};
for(final String h : endToEndHeaders) {
Assertions.assertEquals(HttpTestUtils.getCanonicalHeaderValue(resp1, h),
@ -2823,7 +2808,6 @@ public class TestProtocolRequirements {
resp2.setHeader("Content-Type","text/html");
resp2.setHeader("Expires", DateUtils.formatStandardDate(Instant.now().plusSeconds(5)));
resp2.setHeader("Location", "http://foo.example.com/new2");
resp2.setHeader("Pragma","x-new-pragma");
resp2.setHeader("Retry-After","120");
final ClassicHttpRequest req3 = new BasicClassicHttpRequest("GET", "/");
@ -2839,7 +2823,7 @@ public class TestProtocolRequirements {
final String[] endToEndHeaders = {
"Date", "Cache-Control", "Allow", "Content-Language",
"Content-Location", "Content-Type", "Expires", "Location",
"Pragma", "Retry-After"
"Retry-After"
};
for(final String h : endToEndHeaders) {
Assertions.assertEquals(HttpTestUtils.getCanonicalHeaderValue(resp2, h),
@ -3893,9 +3877,8 @@ public class TestProtocolRequirements {
testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponse(resp1);
}
/* "The request includes a "no-cache" cache-control directive or, for
* compatibility with HTTP/1.0 clients, "Pragma: no-cache".... The
* server MUST NOT use a cached copy when responding to such a request."
/* "The request includes a "no-cache" cache-control directive...
* The server MUST NOT use a cached copy when responding to such a request."
*
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4
*/
@ -3933,13 +3916,6 @@ public class TestProtocolRequirements {
testCacheIsNotUsedWhenRespondingToRequest(req);
}
@Test
public void testCacheIsNotUsedWhenRespondingToRequestWithPragmaNoCache() throws Exception {
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
req.setHeader("Pragma","no-cache");
testCacheIsNotUsedWhenRespondingToRequest(req);
}
/* "When the must-revalidate directive is present in a response received
* by a cache, that cache MUST NOT use the entry after it becomes stale
* to respond to a subsequent request without first revalidating it with