org.apache.nutch.protocol.http.api

## Class HttpRobotRulesParser

- java.lang.Object
- - org.apache.nutch.protocol.RobotRulesParser
  - - org.apache.nutch.protocol.http.api.HttpRobotRulesParser

- All Implemented Interfaces:
    Configurable

      public class HttpRobotRulesParser
      extends RobotRulesParser

  This class is used for parsing robots for urls belonging to HTTP protocol. It extends the generic `RobotRulesParser` class and contains Http protocol specific implementation for obtaining the robots file.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `allowForbidden`

    - ### Fields inherited from class org.apache.nutch.protocol.RobotRulesParser

      `agentNames, CACHE, EMPTY_RULES, FORBID_ALL_RULES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpRobotRulesParser(Configuration conf)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected static java.lang.String` | `getCacheKey(java.net.URL url)` Compose unique key to store and access robot rules in cache for given URL
    `crawlercommons.robots.BaseRobotRules` | `getRobotRulesSet(Protocol http, java.net.URL url)` Get the rules from robots.txt which applies for the given `url`.

    - ### Methods inherited from class org.apache.nutch.protocol.RobotRulesParser

      `getConf, getRobotRulesSet, main, parseRules, setConf`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### allowForbidden

          protected boolean allowForbidden

  - ### Constructor Detail

    - #### HttpRobotRulesParser

          public HttpRobotRulesParser(Configuration conf)

  - ### Method Detail

    - #### getCacheKey

          protected static java.lang.String getCacheKey(java.net.URL url)

      Compose unique key to store and access robot rules in cache for given URL

    - #### getRobotRulesSet

          public crawlercommons.robots.BaseRobotRules getRobotRulesSet(Protocol http,
                                                                       java.net.URL url)

      Get the rules from robots.txt which applies for the given `url`. Robot rules are cached for a unique combination of host, protocol, and port. If no rules are found in the cache, a HTTP request is send to fetch {{protocol://host:port/robots.txt}}. The robots.txt is then parsed and the rules are cached to avoid re-fetching and re-parsing it again.
      Specified by:
        `getRobotRulesSet` in class `RobotRulesParser`
      Parameters:
        `http` - The `Protocol` object
        `url` - URL robots.txt applies to
      Returns:
        `BaseRobotRules` holding the rules from robots.txt

Copyright © 2019 The Apache Software Foundation