Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jasonheecs/httparty into …
Browse files Browse the repository at this point in the history
…jasonheecs-master
  • Loading branch information
jnunemaker committed Mar 20, 2024
2 parents b9bd421 + 01534e5 commit ca47360
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def handle_redirection(&block)
def handle_host_redirection
check_duplicate_location_header
redirect_path = options[:uri_adapter].parse(last_response['location']).normalize
return if redirect_path.relative? || path.host == redirect_path.host
return if redirect_path.relative? || path.host == redirect_path.host || uri.host == redirect_path.host
@changed_hosts = true
end

Expand Down
14 changes: 14 additions & 0 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,20 @@
@request.send(:setup_raw_request)
expect(@request.instance_variable_get(:@raw_request)['authorization']).to eq(@authorization)
end

context 'when uri path is a relative path' do
before do
@request.path = '/v1'
@request.options[:base_uri] = 'http://api.foo.com'
end

it "should send Authorization header when redirecting to the same host" do
@redirect['location'] = 'http://api.foo.com/v2'
@request.perform
@request.send(:setup_raw_request)
expect(@request.instance_variable_get(:@raw_request)['authorization']).to eq(@authorization)
end
end
end
end

Expand Down

0 comments on commit ca47360

Please sign in to comment.