add basic authentication

This commit is contained in:
Ward Wouts 2007-02-24 14:57:47 +00:00
parent 46c0a4caa6
commit 368f45114f

View file

@ -78,14 +78,23 @@ def fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
response = Net::HTTP.get_response(URI.parse(uri_str))
host = URI.parse(uri_str).host
path = URI.parse(uri_str).path
query = URI.parse(uri_str).query
Net::HTTP.start(host) {|http|
req = Net::HTTP::Get.new("#{path}?#{query}")
req.basic_auth @user, @pass
response = http.request(req)
case response
when Net::HTTPSuccess then response
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"; response.error!
when Net::HTTPUnauthorized then puts "401 Authorization Required #{uri_str}"; response.error!
else
response.error!
end
}
end
def deleteold(podcast)
@ -153,6 +162,8 @@ def getcasts(podcast=nil)
files = Array.new
puts podcast
begin
@user = @podcasts[podcast]["username"].nil? ? nil : @podcasts[podcast]["username"]
@pass = @podcasts[podcast]["password"].nil? ? nil : @podcasts[podcast]["password"]
res = fetch(@podcasts[podcast]["rss"])
@filelist = {}