Apache Nutch is an extensible and scalable web crawler
NUTCH-2563 HTTP header spellchecking issues ("Client-Transfer-Encoding" erroneously corrected to "Transfer-Encoding") - limit max. Levenshtein distance to 3 edit operations - add "Client-Transfer-Encoding" to known header fields
Sebastian Nagel381e82ff0a89
diff --git a/src/java/org/apache/nutch/metadata/HttpHeaders.java b/src/java/org/apache/nutch/metadata/HttpHeaders.javaindex a3aec1dbb..b7700e5d3 100644--- a/src/java/org/apache/nutch/metadata/HttpHeaders.java+++ b/src/java/org/apache/nutch/metadata/HttpHeaders.java@@ -28,6 +28,8 @@ public interface HttpHeaders {public static final String TRANSFER_ENCODING = "Transfer-Encoding";+ public static final String CLIENT_TRANSFER_ENCODING = "Client-Transfer-Encoding";+public static final String CONTENT_ENCODING = "Content-Encoding";public static final String CONTENT_LANGUAGE = "Content-Language";diff --git a/src/java/org/apache/nutch/metadata/SpellCheckedMetadata.java b/src/java/org/apache/nutch/metadata/SpellCheckedMetadata.javaindex 9434cab60..fdbf1b62c 100644--- a/src/java/org/apache/nutch/metadata/SpellCheckedMetadata.java+++ b/src/java/org/apache/nutch/metadata/SpellCheckedMetadata.java@@ -32,9 +32,10 @@ import org.apache.commons.lang.StringUtils;public class SpellCheckedMetadata extends Metadata {/**- * Treshold divider.+ * Threshold divider to calculate max. Levenshtein distance for misspelled+ * header field names:*- * <code>threshold = searched.length() / TRESHOLD_DIVIDER;</code>+ * <code>threshold = Math.min(3, searched.length() / TRESHOLD_DIVIDER);</code>*/private static final int TRESHOLD_DIVIDER = 3;@@ -112,7 +113,7 @@ public class SpellCheckedMetadata extends Metadata {String value = NAMES_IDX.get(searched);if ((value == null) && (normalized != null)) {- int threshold = searched.length() / TRESHOLD_DIVIDER;+ int threshold = Math.min(3, searched.length() / TRESHOLD_DIVIDER);for (int i = 0; i < normalized.length && value == null; i++) {if (StringUtils.getLevenshteinDistance(searched, normalized[i]) < threshold) {value = NAMES_IDX.get(normalized[i]);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 844ee90c3..bfc39c25c 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@@ -151,7 +151,8 @@ public class TestBadServerResponses {@Testpublic void testBadHttpServer() throws Exception {setUp();- // test with trivial well-formed content, to make sure the server is responding+ // test with trivial well-formed content, to make sure the server is+ // respondinglaunchServer(responseHeader + simpleContent);fetchPage("/", 200);}@@ -188,6 +189,17 @@ public class TestBadServerResponses {fetchPage("/", 200);}+ /**+ * NUTCH-2563 HTTP header spellchecking issues+ */+ @Test+ public void testHeaderSpellChecking() throws Exception {+ setUp();+ launchServer(responseHeader + "Client-Transfer-Encoding: chunked\r\n"+ + simpleContent);+ fetchPage("/", 200);+ }+/*** NUTCH-2558 protocol-http cannot handle a missing HTTP status line*/