Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Update Commons HTTPClient to v. 3.0.

Andrzej Bialecki4330eef160c9
diff --git a/src/plugin/protocol-httpclient/lib/commons-httpclient-3.0-rc2.jar b/src/plugin/protocol-httpclient/lib/commons-httpclient-3.0-rc2.jar
deleted file mode 100644
index bea0a98a3..000000000
Binary files a/src/plugin/protocol-httpclient/lib/commons-httpclient-3.0-rc2.jar and /dev/null differ
diff --git a/src/plugin/protocol-httpclient/lib/commons-httpclient-3.0.jar b/src/plugin/protocol-httpclient/lib/commons-httpclient-3.0.jar
new file mode 100644
index 000000000..54a9300e6
Binary files /dev/null and b/src/plugin/protocol-httpclient/lib/commons-httpclient-3.0.jar differ
diff --git a/src/plugin/protocol-httpclient/plugin.xml b/src/plugin/protocol-httpclient/plugin.xml
index 951e8d25e..ba0b14c8f 100644
--- a/src/plugin/protocol-httpclient/plugin.xml
+++ b/src/plugin/protocol-httpclient/plugin.xml
@@ -10,7 +10,7 @@
<export name="*"/>
</library>
<library name="commons-codec.jar" />
- <library name="commons-httpclient-3.0-rc2.jar" />
+ <library name="commons-httpclient-3.0.jar" />
</runtime>
<requires>
diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java
index 6df664ec3..f11fd5a64 100644
--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java
+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java
@@ -7,12 +7,14 @@ import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
@@ -358,6 +360,15 @@ public class Http implements org.apache.nutch.protocol.Protocol {
}
HostConfiguration hostConf = client.getHostConfiguration();
+ ArrayList headers = new ArrayList();
+ // prefer English
+ headers.add(new Header("Accept-Language", "en-us,en-gb,en;q=0.7,*;q=0.3"));
+ // prefer UTF-8
+ headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7"));
+ // prefer understandable formats
+ headers.add(new Header("Accept",
+ "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"));
+ hostConf.getParams().setParameter("http.default-headers", headers);
if (PROXY) {
hostConf.setProxy(PROXY_HOST, PROXY_PORT);
}
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 e0035d286..3a5dd10d0 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
@@ -88,7 +88,7 @@ public class HttpResponse {
Header[] heads = get.getResponseHeaders();
for (int i = 0; i < heads.length; i++) {
- headers.put(heads[i].getName(), heads[i].getValue());
+ headers.setProperty(heads[i].getName(), heads[i].getValue());
}
// always read content. Sometimes content is useful to find a cause
// for error.