Skip to content

Commit 93ae369

Browse files
committed
Removed invalid request version check from ResponseCachingPolicy
1 parent 8cec73f commit 93ae369

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ public ResponseCachingPolicy(
9090
* @return {@code true} if response is cacheable
9191
*/
9292
public boolean isResponseCacheable(final ResponseCacheControl cacheControl, final HttpRequest request, final HttpResponse response) {
93-
final ProtocolVersion version = request.getVersion() != null ? request.getVersion() : HttpVersion.DEFAULT;
94-
if (version.compareToVersion(HttpVersion.HTTP_1_1) > 0) {
95-
if (LOG.isDebugEnabled()) {
96-
LOG.debug("Protocol version {} is non-cacheable", version);
97-
}
98-
return false;
99-
}
100-
10193
// Presently only GET and HEAD methods are supported
10294
final String httpMethod = request.getMethod();
10395
if (!Method.GET.isSame(httpMethod) && !Method.HEAD.isSame(httpMethod)) {

httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseCachingPolicy.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,4 +1000,20 @@ void testMustRevalidateWithAuthorizationIsCacheable() {
10001000
"Response with must-revalidate and Authorization header should be cacheable in shared cache.");
10011001
}
10021002

1003+
@Test
1004+
void testHttp2_0HintCacheable() {
1005+
request = new BasicHttpRequest("GET", "/");
1006+
request.setVersion(HttpVersion.HTTP_2);
1007+
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
1008+
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
1009+
}
1010+
1011+
@Test
1012+
void testHttp1_0HintCacheable() {
1013+
request = new BasicHttpRequest("GET", "/");
1014+
request.setVersion(HttpVersion.HTTP_1_0);
1015+
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
1016+
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
1017+
}
1018+
10031019
}

0 commit comments

Comments
 (0)