Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH 1921 Optionally disable HTTP if-modified-since header

Markus Jelsma6a676a7c4e7c
diff --git a/CHANGES.txt b/CHANGES.txt
index cb81052b8..39ba3155f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Nutch Current Development 1.10-SNAPSHOT
+* NUTCH-1921 Optionally disable HTTP if-modified-since header (markus)
+
* NUTCH-1933 nutch-selenium plugin (Mo Omer, Mohammad Al-Moshin, lewismc)
* NUTCH-827 HTTP POST Authentication (Jasper van Veghel, yuanyun.cn, snagel, lewismc)
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 590a3659a..6a8ab093d 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -297,6 +297,17 @@
</description>
</property>
+<property>
+ <name>http.enable.if.modified.since.header</name>
+ <value>true</value>
+ <description>Whether Nutch sends an HTTP If-Modified-Since header. It reduces
+ bandwidth when enabled by not downloading pages that respond with an HTTP
+ Not-Modified header. URL's that are not downloaded are not passed through
+ parse or indexing filters. If you regularly modify filters, you should force
+ Nutch to also download unmodified pages by disabling this feature.
+ </description>
+</property>
+
<!-- FTP properties -->
<property>
diff --git a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
index 557ed79f0..846be0eef 100644
--- a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
+++ b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
@@ -107,6 +107,9 @@ public abstract class HttpBase implements Protocol {
/** Which TLS/SSL cipher suites to support */
protected Set<String> tlsPreferredCipherSuites;
+
+ /** Configuration directive for If-Modified-Since HTTP header */
+ public boolean enableIfModifiedsinceHeader = true;
/** Creates a new instance of HttpBase */
public HttpBase() {
@@ -137,6 +140,7 @@ public abstract class HttpBase implements Protocol {
// backward-compatible default setting
this.useHttp11 = conf.getBoolean("http.useHttp11", false);
this.responseTime = conf.getBoolean("http.store.responsetime", true);
+ this.enableIfModifiedsinceHeader = conf.getBoolean("http.enable.if.modified.since.header", true);
this.robots.setConf(conf);
String[] protocols = conf.getStrings("http.tls.supported.protocols",
@@ -298,6 +302,10 @@ public abstract class HttpBase implements Protocol {
public int getTimeout() {
return timeout;
}
+
+ public boolean isIfModifiedSinceEnabled() {
+ return enableIfModifiedsinceHeader;
+ }
public int getMaxContent() {
return maxContent;
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 e3298028d..331f2a352 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
@@ -192,7 +192,7 @@ public class HttpResponse implements Response {
reqStr.append(this.http.getAccept());
reqStr.append("\r\n");
- if (datum.getModifiedTime() > 0) {
+ if (http.isIfModifiedSinceEnabled() && datum.getModifiedTime() > 0) {
reqStr.append("If-Modified-Since: "
+ HttpDateFormat.toString(datum.getModifiedTime()));
reqStr.append("\r\n");
diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.java
index b6ec45124..e6a4c35db 100644
--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.java
+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpResponse.java
@@ -74,7 +74,7 @@ public class HttpResponse implements Response {
GetMethod get = new GetMethod(url.toString());
get.setFollowRedirects(followRedirects);
get.setDoAuthentication(true);
- if (datum.getModifiedTime() > 0) {
+ if (http.isIfModifiedSinceEnabled() && datum.getModifiedTime() > 0) {
get.setRequestHeader("If-Modified-Since",
HttpDateFormat.toString(datum.getModifiedTime()));
}