mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Merge pull request #333 from jrafanie/fix_unwrapped_ipv6_host_field_in_request_header
ruby 2+: delegate IPv6 [] wrapping to net/http by passing a URI object.
This commit is contained in:
commit
4cc904f230
2 changed files with 20 additions and 1 deletions
|
@ -172,7 +172,11 @@ module RestClient
|
|||
|
||||
def execute & block
|
||||
uri = parse_url_with_auth(url)
|
||||
transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
|
||||
|
||||
# With 2.0.0+, net/http accepts URI objects in requests and handles wrapping
|
||||
# IPv6 addresses in [] for use in the Host request header.
|
||||
request_uri = RUBY_VERSION >= "2.0.0" ? uri : uri.request_uri
|
||||
transmit uri, net_http_request_class(method).new(request_uri, processed_headers), payload, & block
|
||||
ensure
|
||||
payload.close if payload
|
||||
end
|
||||
|
|
|
@ -260,6 +260,21 @@ describe RestClient::Request do
|
|||
@request.execute
|
||||
end
|
||||
|
||||
it "IPv6: executes by constructing the Net::HTTP object, headers, and payload and calling transmit" do
|
||||
@request = RestClient::Request.new(:method => :put, :url => 'http://[::1]/some/resource', :payload => 'payload')
|
||||
klass = double("net:http class")
|
||||
@request.should_receive(:net_http_request_class).with(:put).and_return(klass)
|
||||
|
||||
if RUBY_VERSION >= "2.0.0"
|
||||
klass.should_receive(:new).with(kind_of(URI), kind_of(Hash)).and_return('result')
|
||||
else
|
||||
klass.should_receive(:new).with(kind_of(String), kind_of(Hash)).and_return('result')
|
||||
end
|
||||
|
||||
@request.should_receive(:transmit)
|
||||
@request.execute
|
||||
end
|
||||
|
||||
it "transmits the request with Net::HTTP" do
|
||||
@http.should_receive(:request).with('req', 'payload')
|
||||
@request.should_receive(:process_result)
|
||||
|
|
Loading…
Add table
Reference in a new issue