Apache Nutch is an extensible and scalable web crawler
NUTCH-731 Redirection of robots.txt in RobotRulesParser.
Andrzej Bialecki84821e7d2ad2
diff --git a/CHANGES.txt b/CHANGES.txtindex d1aa22792..547df806f 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -15,6 +15,8 @@ Unreleased Changes* NUTCH-730 - NPE in LinkRank if no nodes with which to create the WebGraph(Dennis Kubes via ab)+* NUTCH-731 - Redirection of robots.txt in RobotRulesParser (Julien Nioche via ab)+Release 1.0 - 2009-03-231. NUTCH-474 - Fetcher2 crawlDelay and blocking fix (Dogacan Guney via ab)diff --git a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.javaindex 8f652f117..7dd1373fe 100644--- a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java+++ b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java@@ -434,10 +434,29 @@ public class RobotRulesParser implements Configurable {boolean cacheRule = true;if (robotRules == null) { // cache miss+ URL redir = null;if (LOG.isTraceEnabled()) { LOG.trace("cache miss " + url); }try {Response response = http.getResponse(new URL(url, "/robots.txt"),new CrawlDatum(), true);+ // try one level of redirection ?+ if (response.getCode() == 301 || response.getCode() == 302) {+ String redirection = response.getHeader("Location");+ if (redirection == null) {+ // some versions of MS IIS are known to mangle this header+ redirection = response.getHeader("location");+ }+ if (redirection != null) {+ if (!redirection.startsWith("http")) {+ // RFC says it should be absolute, but apparently it isn't+ redir = new URL(url, redirection);+ } else {+ redir = new URL(redirection);+ }++ response = http.getResponse(redir, new CrawlDatum(), true);+ }+ }if (response.getCode() == 200) // found rules: parse themrobotRules = parseRules(response.getContent());@@ -456,8 +475,12 @@ public class RobotRulesParser implements Configurable {robotRules = EMPTY_RULES;}- if (cacheRule){+ if (cacheRule) {CACHE.put(host, robotRules); // cache rules for host+ if (redir != null && !redir.getHost().equals(host)) {+ // cache also for the redirected host+ CACHE.put(redir.getHost(), robotRules);+ }}}return robotRules;