add basic authentication
This commit is contained in:
parent
46c0a4caa6
commit
368f45114f
1 changed files with 20 additions and 9 deletions
|
|
@ -78,14 +78,23 @@ def fetch(uri_str, limit = 10)
|
||||||
# You should choose better exception.
|
# You should choose better exception.
|
||||||
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
|
||||||
|
|
||||||
response = Net::HTTP.get_response(URI.parse(uri_str))
|
host = URI.parse(uri_str).host
|
||||||
case response
|
path = URI.parse(uri_str).path
|
||||||
when Net::HTTPSuccess then response
|
query = URI.parse(uri_str).query
|
||||||
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
|
|
||||||
when Net::HTTPNotFound then puts "404 Not Found #{uri_str}"; response.error!
|
Net::HTTP.start(host) {|http|
|
||||||
else
|
req = Net::HTTP::Get.new("#{path}?#{query}")
|
||||||
response.error!
|
req.basic_auth @user, @pass
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def deleteold(podcast)
|
def deleteold(podcast)
|
||||||
|
|
@ -153,9 +162,11 @@ def getcasts(podcast=nil)
|
||||||
files = Array.new
|
files = Array.new
|
||||||
puts podcast
|
puts podcast
|
||||||
begin
|
begin
|
||||||
|
@user = @podcasts[podcast]["username"].nil? ? nil : @podcasts[podcast]["username"]
|
||||||
|
@pass = @podcasts[podcast]["password"].nil? ? nil : @podcasts[podcast]["password"]
|
||||||
res = fetch(@podcasts[podcast]["rss"])
|
res = fetch(@podcasts[podcast]["rss"])
|
||||||
@filelist = {}
|
@filelist = {}
|
||||||
|
|
||||||
# body.gsub!(/#{13.chr}#{10.chr}/, "#{10.chr}")
|
# body.gsub!(/#{13.chr}#{10.chr}/, "#{10.chr}")
|
||||||
xmldoc = REXML::Document.new(res.body)
|
xmldoc = REXML::Document.new(res.body)
|
||||||
xmldoc.elements.each("rss/channel") {|item|
|
xmldoc.elements.each("rss/channel") {|item|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue