Apache Nutch is an extensible and scalable web crawler
NUTCH-2559 protocol-http cannot handle colons after the HTTP status code (patch contributed by Gerard Bouchar)
Sebastian Nagel9e212a267523
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 e6460bccc..92430ba11 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@@ -501,36 +501,29 @@ public class HttpResponse implements Response {readLine(in, line, false);int codeStart = line.indexOf(" ");- int codeEnd = line.indexOf(" ", codeStart + 1);-- // handle lines with no plaintext result code, ie:- // "HTTP/1.1 200" vs "HTTP/1.1 200 OK"- if (codeEnd == -1)- codeEnd = line.length();+ int codeEnd;+ int lineLength = line.length();++ // We want to handle lines like "HTTP/1.1 200", "HTTP/1.1 200 OK", or "HTTP/1.1 404: Not Found"+ for (codeEnd = codeStart + 1; codeEnd < lineLength; codeEnd++) {+ if (!Character.isDigit(line.charAt(codeEnd))) break;+ // Note: input is plain ASCII and may not contain Arabic etc. digits+ // covered by Character.isDigit()+ }- int code;try {- code = Integer.parseInt(line.substring(codeStart + 1, codeEnd));+ return Integer.parseInt(line.substring(codeStart + 1, codeEnd));} catch (NumberFormatException e) {- throw new HttpException(- "bad status line '" + line + "': " + e.getMessage(), e);+ throw new HttpException("bad status line '" + line + "'" + e.getMessage(), e);}-- return code;}- private void processHeaderLine(StringBuffer line)- throws IOException, HttpException {+ private void processHeaderLine(StringBuffer line) {int colonIndex = line.indexOf(":"); // key is up to colonif (colonIndex == -1) {- int i;- for (i = 0; i < line.length(); i++)- if (!Character.isWhitespace(line.charAt(i)))- break;- if (i == line.length())- return;- throw new HttpException("No colon in header:" + line);+ Http.LOG.info("Ignoring a header line without a colon: '{}'", line);+ return;}String key = line.substring(0, colonIndex);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 cf3b8052f..1f9606777 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@@ -184,6 +184,19 @@ public class TestBadServerResponses {fetchPage("/", 200);}+ /**+ * NUTCH-2559 protocol-http cannot handle colons after the HTTP status code+ */+ @Test+ public void testHeaderWithColon() throws Exception {+ setUp();+ launchServer("HTTP/1.1 200: OK\r\n" + simpleContent);+ fetchPage("/", 200);+ server.close();+ launchServer("HTTP/1.1 \u0966\u0967\u0968: OK\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