Apache Nutch is an extensible and scalable web crawler
NUTCH-1310 Nutch to send HTTP-accept header
Markus Jelsma2563a054ba45
diff --git a/CHANGES.txt b/CHANGES.txtindex 2519f4fea..6ee35a8dc 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -1,5 +1,7 @@Nutch Change Log+* NUTCH-1310 Nutch to send HTTP-accept header (markus)+* NUTCH-1305 Domain(blacklist)URLFilter to trim entries (markus)* NUTCH-1307 Improve formatting of ant targets for clearer project help (lewismc)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex cc9fe7a8b..bb134202a 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -248,6 +248,13 @@</description></property>+<property>+ <name>http.accept</name>+ <value>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</value>+ <description>Value of the "Accept" request header field.+ </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.javaindex e6908502f..44f99b7ea 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@@ -76,6 +76,9 @@ public abstract class HttpBase implements Protocol {/** The "Accept-Language" request header value. */protected String acceptLanguage = "en-us,en-gb,en;q=0.7,*;q=0.3";++ /** The "Accept" request header value. */+ protected String accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";/** The default logger */private final static Logger LOGGER = LoggerFactory.getLogger(HttpBase.class);@@ -105,22 +108,23 @@ public abstract class HttpBase implements Protocol {robots = new RobotRulesParser();}- // Inherited Javadoc- public void setConf(Configuration conf) {- this.conf = conf;- this.proxyHost = conf.get("http.proxy.host");- this.proxyPort = conf.getInt("http.proxy.port", 8080);- this.useProxy = (proxyHost != null && proxyHost.length() > 0);- this.timeout = conf.getInt("http.timeout", 10000);- this.maxContent = conf.getInt("http.content.limit", 64 * 1024);- this.userAgent = getAgentString(conf.get("http.agent.name"), conf.get("http.agent.version"), conf- .get("http.agent.description"), conf.get("http.agent.url"), conf.get("http.agent.email"));- this.acceptLanguage = conf.get("http.accept.language", acceptLanguage);- // backward-compatible default setting- this.useHttp11 = conf.getBoolean("http.useHttp11", false);- this.robots.setConf(conf);- logConf();- }+ // Inherited Javadoc+ public void setConf(Configuration conf) {+ this.conf = conf;+ this.proxyHost = conf.get("http.proxy.host");+ this.proxyPort = conf.getInt("http.proxy.port", 8080);+ this.useProxy = (proxyHost != null && proxyHost.length() > 0);+ this.timeout = conf.getInt("http.timeout", 10000);+ this.maxContent = conf.getInt("http.content.limit", 64 * 1024);+ this.userAgent = getAgentString(conf.get("http.agent.name"), conf.get("http.agent.version"), conf+ .get("http.agent.description"), conf.get("http.agent.url"), conf.get("http.agent.email"));+ this.acceptLanguage = conf.get("http.accept.language", acceptLanguage);+ this.accept = conf.get("http.accept", accept);+ // backward-compatible default setting+ this.useHttp11 = conf.getBoolean("http.useHttp11", false);+ this.robots.setConf(conf);+ logConf();+ }// Inherited Javadocpublic Configuration getConf() {@@ -235,6 +239,10 @@ public abstract class HttpBase implements Protocol {return acceptLanguage;}+ public String getAccept() {+ return accept;+ }+public boolean getUseHttp11() {return useHttp11;}@@ -292,6 +300,7 @@ public abstract class HttpBase implements Protocol {logger.info("http.content.limit = " + maxContent);logger.info("http.agent = " + userAgent);logger.info("http.accept.language = " + acceptLanguage);+ logger.info("http.accept = " + accept);}}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 9f1ff5ef8..2b964b909 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@@ -50,7 +50,6 @@ public class HttpResponse implements Response {private int code;private Metadata headers = new SpellCheckedMetadata();-public HttpResponse(HttpBase http, URL url, CrawlDatum datum)throws ProtocolException, IOException {@@ -122,11 +121,15 @@ public class HttpResponse implements Response {reqStr.append(userAgent);reqStr.append("\r\n");}-+reqStr.append("Accept-Language: ");reqStr.append(this.http.getAcceptLanguage());reqStr.append("\r\n");+ reqStr.append("Accept: ");+ reqStr.append(this.http.getAccept());+ reqStr.append("\r\n");+if (datum.getModifiedTime() > 0) {reqStr.append("If-Modified-Since: " + HttpDateFormat.toString(datum.getModifiedTime()));reqStr.append("\r\n");