]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Support basic_auth in httputil get and head methods
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 24 Oct 2006 00:14:54 +0000 (00:14 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 24 Oct 2006 00:14:54 +0000 (00:14 +0000)
lib/rbot/httputil.rb

index e80a45aa388fa4a48e3244f280f1101c6b65c389..18fc6a554f9e0a9dcf2d490203f1cff335c8aa84 100644 (file)
@@ -152,7 +152,11 @@ class HttpUtil
     begin
       proxy.start() {|http|
         yield uri.request_uri() if block_given?
     begin
       proxy.start() {|http|
         yield uri.request_uri() if block_given?
-        resp = http.get(uri.request_uri(), @headers)
+       req = Net::HTTP::Get.new(uri.request_uri(), @headers)
+       if uri.user and uri.password
+          req.basic_auth(uri.user, uri.password)
+       end
+       resp = http.request(req)
         case resp
         when Net::HTTPSuccess
           if cache && !(resp.key?('cache-control') && resp['cache-control']=='must-revalidate')
         case resp
         when Net::HTTPSuccess
           if cache && !(resp.key?('cache-control') && resp['cache-control']=='must-revalidate')
@@ -208,7 +212,11 @@ class HttpUtil
     begin
       proxy.start() {|http|
         yield uri.request_uri() if block_given?
     begin
       proxy.start() {|http|
         yield uri.request_uri() if block_given?
-        resp = http.request_head(uri.request_uri(), @headers)
+       req = Net::HTTP::Head.new(uri.request_uri(), @headers)
+       if uri.user and uri.password
+          req.basic_auth(uri.user, uri.password)
+       end
+       resp = http.request(req)
         case resp
         when Net::HTTPSuccess
           return resp
         case resp
         when Net::HTTPSuccess
           return resp