summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-18 11:57:38 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-18 11:57:38 +0000
commit43e4e6b7b88846879e2aab6377ad6fe1621bb12e (patch)
treec6e6bcf3a06b9c235fc6f9be72891a91624ade2b /lib
parent6aa7d400a8b519ba090a9d52ffb00051af3be5cb (diff)
Comments updated.
Diffstat (limited to 'lib')
-rw-r--r--[-rwxr-xr-x]lib/custodian/webfetch.rb36
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