Skip to content

Commit

Permalink
* Cookie header is not set in authentication negotiation. do not reu…
Browse files Browse the repository at this point in the history
…se request object in negotiations. closes nahi#210.
  • Loading branch information
nahi committed May 14, 2009
1 parent 4d3c829 commit cf55b01
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/httpclient.rb
Expand Up @@ -752,10 +752,14 @@ class KeepAliveDisconnected < StandardError # :nodoc:
def do_request(method, uri, query, body, extheader, &block)
conn = Connection.new
res = nil
if HTTP::Message.file?(body)
pos = body.pos rescue nil
end
retry_count = @session_manager.protocol_retry_count
proxy = no_proxy?(uri) ? nil : @proxy
req = create_request(method, uri, query, body, extheader)
while retry_count > 0
body.pos = pos if pos
req = create_request(method, uri, query, body, extheader)
begin
protect_keep_alive_disconnected do
do_get_block(req, proxy, conn, &block)
Expand All @@ -773,10 +777,14 @@ def do_request(method, uri, query, body, extheader, &block)
def do_request_async(method, uri, query, body, extheader)
conn = Connection.new
t = Thread.new(conn) { |tconn|
if HTTP::Message.file?(body)
pos = body.pos rescue nil
end
retry_count = @session_manager.protocol_retry_count
proxy = no_proxy?(uri) ? nil : @proxy
req = create_request(method, uri, query, body, extheader)
while retry_count > 0
body.pos = pos if pos
req = create_request(method, uri, query, body, extheader)
begin
protect_keep_alive_disconnected do
do_get_stream(req, proxy, tconn)
Expand Down
27 changes: 27 additions & 0 deletions test/test_httpclient.rb
Expand Up @@ -262,6 +262,33 @@ def test_no_proxy
end
end

def test_cookie_update_while_authentication
escape_noproxy do
@client.test_loopback_http_response << <<EOS
HTTP/1.0 401\r
Date: Fri, 19 Dec 2008 11:57:29 GMT\r
Content-Type: text/plain\r
Content-Length: 0\r
WWW-Authenticate: Basic realm="hello"\r
Set-Cookie: foo=bar; path=/; domain=.example.org; expires=#{Time.mktime(2030, 12, 31).httpdate}\r
\r
EOS
@client.test_loopback_http_response << <<EOS
HTTP/1.1 200 OK\r
Content-Length: 5\r
Connection: close\r
\r
hello
EOS
@client.debug_dev = str = ''
@client.set_auth("http://www.example.org/baz/", 'admin', 'admin')
assert_equal('hello', @client.get('http://www.example.org/baz/foo').content)
assert_match(/^Cookie: foo=bar/, str)
assert_match(/^Authorization: Basic YWRtaW46YWRtaW4=/, str)
end
end


def test_proxy_ssl
escape_noproxy do
@client.proxy = 'http://admin:admin@localhost:8080/'
Expand Down

0 comments on commit cf55b01

Please sign in to comment.