forked from Archives/Athou_commafeed
ignore invalid cache control values (#1619)
This commit is contained in:
@@ -162,7 +162,7 @@ public class HttpGetter {
|
|||||||
CacheControl cacheControl = Optional.ofNullable(resp.getFirstHeader(HttpHeaders.CACHE_CONTROL))
|
CacheControl cacheControl = Optional.ofNullable(resp.getFirstHeader(HttpHeaders.CACHE_CONTROL))
|
||||||
.map(NameValuePair::getValue)
|
.map(NameValuePair::getValue)
|
||||||
.map(StringUtils::trimToNull)
|
.map(StringUtils::trimToNull)
|
||||||
.map(CacheControlDelegate.INSTANCE::fromString)
|
.map(HttpGetter::toCacheControl)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
String contentType = Optional.ofNullable(resp.getEntity()).map(HttpEntity::getContentType).orElse(null);
|
String contentType = Optional.ofNullable(resp.getEntity()).map(HttpEntity::getContentType).orElse(null);
|
||||||
@@ -176,6 +176,15 @@ public class HttpGetter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static CacheControl toCacheControl(String headerValue) {
|
||||||
|
try {
|
||||||
|
return CacheControlDelegate.INSTANCE.fromString(headerValue);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("Invalid Cache-Control header: {}", headerValue);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static byte[] toByteArray(HttpEntity entity, long maxBytes) throws IOException {
|
private static byte[] toByteArray(HttpEntity entity, long maxBytes) throws IOException {
|
||||||
if (entity.getContentLength() > maxBytes) {
|
if (entity.getContentLength() > maxBytes) {
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class HttpGetterTest {
|
|||||||
.withContentType(MediaType.APPLICATION_ATOM_XML)
|
.withContentType(MediaType.APPLICATION_ATOM_XML)
|
||||||
.withHeader(HttpHeaders.LAST_MODIFIED, "123456")
|
.withHeader(HttpHeaders.LAST_MODIFIED, "123456")
|
||||||
.withHeader(HttpHeaders.ETAG, "78910")
|
.withHeader(HttpHeaders.ETAG, "78910")
|
||||||
.withHeader(HttpHeaders.CACHE_CONTROL, "max-age=60"));
|
.withHeader(HttpHeaders.CACHE_CONTROL, "max-age=60, must-revalidate"));
|
||||||
|
|
||||||
HttpResult result = getter.get(this.feedUrl);
|
HttpResult result = getter.get(this.feedUrl);
|
||||||
Assertions.assertArrayEquals(feedContent, result.getContent());
|
Assertions.assertArrayEquals(feedContent, result.getContent());
|
||||||
@@ -105,6 +105,18 @@ class HttpGetterTest {
|
|||||||
Assertions.assertEquals(this.feedUrl, result.getUrlAfterRedirect());
|
Assertions.assertEquals(this.feedUrl, result.getUrlAfterRedirect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ignoreInvalidCacheControlValue() throws Exception {
|
||||||
|
this.mockServerClient.when(HttpRequest.request().withMethod("GET"))
|
||||||
|
.respond(HttpResponse.response()
|
||||||
|
.withBody(feedContent)
|
||||||
|
.withContentType(MediaType.APPLICATION_ATOM_XML)
|
||||||
|
.withHeader(HttpHeaders.CACHE_CONTROL, "max-age=60; must-revalidate"));
|
||||||
|
|
||||||
|
HttpResult result = getter.get(this.feedUrl);
|
||||||
|
Assertions.assertEquals(Duration.ZERO, result.getValidFor());
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(
|
@ValueSource(
|
||||||
ints = { HttpStatus.SC_MOVED_PERMANENTLY, HttpStatus.SC_MOVED_TEMPORARILY, HttpStatus.SC_TEMPORARY_REDIRECT,
|
ints = { HttpStatus.SC_MOVED_PERMANENTLY, HttpStatus.SC_MOVED_TEMPORARILY, HttpStatus.SC_TEMPORARY_REDIRECT,
|
||||||
|
|||||||
Reference in New Issue
Block a user