Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2562 protocol-http fails to read large chunked HTTP responses - if http.content.limit is reached skip remaining chunked content including any headers in the trailer

Sebastian Nagelc658d753635e
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.java
index 591b94298..56ae789f3 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
@@ -437,9 +437,11 @@ public class HttpResponse implements Response {
break;
}
- if (http.getMaxContent() >= 0 && (contentBytesRead + chunkLen) > http
- .getMaxContent())
+ if (http.getMaxContent() >= 0
+ && (contentBytesRead + chunkLen) > http.getMaxContent()) {
+ // content will be trimmed when processing this chunk
chunkLen = http.getMaxContent() - contentBytesRead;
+ }
// read one chunk
int chunkBytesRead = 0;
@@ -465,17 +467,26 @@ public class HttpResponse implements Response {
}
contentBytesRead += chunkBytesRead;
+ if (http.getMaxContent() >= 0
+ && contentBytesRead >= http.getMaxContent()) {
+ Http.LOG.trace("Http: content limit reached");
+ break;
+ }
+
readLine(in, line, false);
}
+ content = out.toByteArray();
+
if (!doneChunks) {
+ // content trimmed
if (contentBytesRead != http.getMaxContent())
throw new HttpException("chunk eof: !doneChunk && didn't max out");
return;
}
- content = out.toByteArray();
+ // read trailing headers
parseHeaders(in, line, null);
}