Apache Nutch is an extensible and scalable web crawler
NUTCH-2564 protocol-http throws an error when the content-length header is not a number - ignore invalid Content-Length header (log warning instead of throwing exception)
Sebastian Nagel957306ae0399
diff --git a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.javaindex a5594a3e8..e6460bccc 100644--- a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java+++ b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java@@ -356,10 +356,11 @@ public class HttpResponse implements Response {if (contentLengthString != null) {contentLengthString = contentLengthString.trim();try {- if (!contentLengthString.isEmpty())+ if (!contentLengthString.isEmpty()) {contentLength = Integer.parseInt(contentLengthString);+ }} catch (NumberFormatException e) {- throw new HttpException("bad content length: " + contentLengthString);+ Http.LOG.warn("bad content length: {}", contentLengthString);}}if (http.getMaxContent() >= 0 && contentLength > http.getMaxContent()) {diff --git a/src/plugin/protocol-http/src/test/org/apache/nutch/protocol/http/TestBadServerResponses.java b/src/plugin/protocol-http/src/test/org/apache/nutch/protocol/http/TestBadServerResponses.javaindex 10de27c9e..cf3b8052f 100644--- a/src/plugin/protocol-http/src/test/org/apache/nutch/protocol/http/TestBadServerResponses.java+++ b/src/plugin/protocol-http/src/test/org/apache/nutch/protocol/http/TestBadServerResponses.java@@ -172,6 +172,18 @@ public class TestBadServerResponses {fetchPage("?171", 200);}+ /**+ * NUTCH-2564 protocol-http throws an error when the content-length header is+ * not a number+ */+ @Test+ public void testContentLengthNotANumber() throws Exception {+ setUp();+ launchServer(+ responseHeader + "Content-Length: thousand\r\n" + simpleContent);+ fetchPage("/", 200);+ }+/*** NUTCH-2562 protocol-http fails to read large chunked HTTP responses,* NUTCH-2575 protocol-http does not respect the maximum content-size for