diff options
| author | Steve Kemp <steve@steve.org.uk> | 2012-11-18 11:57:38 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2012-11-18 11:57:38 +0000 | 
| commit | e360a2885bf9ff674b83b2d5f8c4d5f79d1204e4 (patch) | |
| tree | c6e6bcf3a06b9c235fc6f9be72891a91624ade2b | |
| parent | eeaaca61a9fa9df24c422ebe229a6b9928f60f20 (diff) | |
  Comments updated.
| -rw-r--r--[-rwxr-xr-x] | lib/custodian/webfetch.rb | 36 | 
1 files changed, 26 insertions, 10 deletions
| diff --git a/lib/custodian/webfetch.rb b/lib/custodian/webfetch.rb index 0b5f9c6..8948958 100755..100644 --- a/lib/custodian/webfetch.rb +++ b/lib/custodian/webfetch.rb @@ -4,6 +4,17 @@  require 'tempfile' +# +# This is a class which allows a remote HTTP/HTTPS page to be downloaded +# it allows both the content and the HTTP status-code to be retrieved assuming +# a success was made. +# +# This code is *horrificly* bad, but required because net/http doesn't honour +# timouts under certain circumstances.  I'm not proud of this code. +# +# Steve +# --  +#  class WebFetch    # @@ -14,7 +25,12 @@ class WebFetch    #    # The HTTP status code, and content, we received from fetching the URL    # -  attr_reader :status, :text, :error +  attr_reader :status, :text + +  # +  # An error to return to the caller, on failure +  # +  attr_reader :error @@ -34,9 +50,7 @@ class WebFetch    # -  # Perform the fetch. -  # -  # Return true on success. +  # Perform the fetch of the remote URL.  Return "true" on success.    #    def fetch @@ -72,9 +86,9 @@ class WebFetch        File.unlink( head ) if ( File.exists?( head ) )        # -      # Save the error. +      # Store the error.        # -      @error = "Fetch failed" +      @error = "Fetch of #{@url} failed"        return false      end @@ -82,6 +96,10 @@ class WebFetch      #      #  Get the HTTP status code, by parsing the HTTP headers.      # +    #  NOTE: We will replace the code with later ones - this gives +    #  the status code *after* any potential redirection(s) have +    #  completed. +    #      File.open( head, "r").each_line do |line|        if ( line =~ /HTTP\/[0-9]\.[0-9]\s+([0-9]+)\s+/ )          @status = $1.dup @@ -106,16 +124,14 @@ class WebFetch    # -  # Return the HTTP status code the server responded with, if the -  # fetch was successful. +  # Return the HTTP status code the server responded with, if the fetch was successful.    #    def status      @status    end    # -  # Return the HTTP content the server responded with, if the -  # fetch was successful. +  # Return the HTTP content the server responded with, if the fetch was successful.    #    def content      @text | 
