From e360a2885bf9ff674b83b2d5f8c4d5f79d1204e4 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sun, 18 Nov 2012 11:57:38 +0000 Subject: Comments updated. --- lib/custodian/webfetch.rb | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) mode change 100755 => 100644 lib/custodian/webfetch.rb (limited to 'lib') diff --git a/lib/custodian/webfetch.rb b/lib/custodian/webfetch.rb old mode 100755 new mode 100644 index 0b5f9c6..8948958 --- 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 -- cgit v1.2.1