Permalink
Browse files

Fixed NME for non absolute-URI redirect on https. closes #20.

  • Loading branch information...
1 parent 6f48800 commit 8a94b2116ee33799bc019722583f48ca731b74be @nahi committed Dec 12, 2010
Showing with 12 additions and 3 deletions.
  1. +3 −3 lib/httpclient.rb
  2. +9 −0 test/test_httpclient.rb
View
@@ -571,14 +571,14 @@ def strict_redirect_uri_callback(uri, res)
# in HTTP header.
def default_redirect_uri_callback(uri, res)
newuri = URI.parse(res.header['location'][0])
- if https?(uri) && !https?(newuri)
- raise BadResponseError.new("redirecting to non-https resource")
- end
unless newuri.is_a?(URI::HTTP)
newuri = uri + newuri
STDERR.puts("could be a relative URI in location header which is not recommended")
STDERR.puts("'The field value consists of a single absolute URI' in HTTP spec")
end
+ if https?(uri) && !https?(newuri)
+ raise BadResponseError.new("redirecting to non-https resource")
+ end
puts "redirect to: #{newuri}" if $DEBUG
newuri
end
View
@@ -434,6 +434,15 @@ def test_redirect_relative
end
end
+ def test_redirect_https_relative
+ url = @url + 'redirect1'
+ https_url = URI.parse(url)
+ https_url.scheme = 'https'
+ @client.test_loopback_http_response << "HTTP/1.0 302 OK\nLocation: /foo\n\n"
+ @client.test_loopback_http_response << "HTTP/1.0 200 OK\n\nhello"
+ assert_equal('hello', @client.get_content(https_url))
+ end
+
def test_no_content
assert_nothing_raised do
timeout(2) do

0 comments on commit 8a94b21

Please sign in to comment.