diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-04-21 11:11:40 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-04-21 11:11:40 +0000 |
commit | aa18a307bfe8d796605146549a30eab5ede97110 (patch) | |
tree | f3d029fb2d8737756ca9e9e59dd8e445067a4317 /lib/open-uri.rb | |
parent | 86c42378d1c149f758555fbcae16f571c6c4b9e6 (diff) |
* lib/open-uri.rb (URI::HTTP#proxy_open): set Host: field explicitly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/open-uri.rb')
-rw-r--r-- | lib/open-uri.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 9523a17458..a6186fbb2c 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -1,7 +1,7 @@ #= open-uri.rb # #open-uri.rb is easy-to-use wrapper for net/http and net/ftp. -# +# #== Example # #It is possible to open http/ftp URL as usual a file: @@ -40,7 +40,7 @@ # } # #URI objects can be opened in similar way. -# +# # uri = URI.parse("http://www.ruby-lang.org/en/") # uri.open {|f| # ... @@ -66,7 +66,7 @@ module Kernel # If the first argument respond to `open' method, # the method is called with the rest arguments. # - # If the first argument is a string which begins with xxx://, + # If the first argument is a string which begins with xxx://, # it is parsed by URI.parse. If the parsed object respond to `open' method, # the method is called with the rest arguments. # @@ -181,7 +181,7 @@ module OpenURI end uri = redirect raise "HTTP redirection loop: #{uri}" if uri_set.include? uri.to_s - uri_set[uri.to_s] = true + uri_set[uri.to_s] = true else break end @@ -501,7 +501,7 @@ module URI if proxy_uri proxy_uri = URI.parse(proxy_uri) unless URI::HTTP === proxy_uri - raise "Non-http proxy URI: #{proxy_uri}" + raise "Non-HTTP proxy URI: #{proxy_uri}" end name = 'no_proxy' if no_proxy = ENV[name] || ENV[name.upcase] @@ -529,6 +529,16 @@ module URI header = {} options.each {|k, v| header[k] = v if String === k } + if uri.respond_to? :host + # According to RFC2616 14.23, Host: request-header field should be set + # an origin server. + # But net/http wrongly set a proxy server if an absolute URI is + # specified as a request URI. + # So open-uri override it here explicitly. + header['host'] = uri.host + header['host'] += ":#{uri.port}" if uri.port + end + require 'net/http' resp = nil Net::HTTP.start(self.host, self.port) {|http| |