Skip to content

Commit 3aae264

Browse files
Response#uri can be set directly, or pulled from the Request
During normal operation, the Response#uri will be pulled from the Request passed into the Response. However, we still allow explicitly setting a `:uri` option when creating a Response, for backwards compatibility. This was motivated by rubocop/code climate complaining that `Client#perform` was now 1-line too long. I'll defer to the project maintainers to decide if that is a good thing.
1 parent 3624f90 commit 3aae264

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/http/client.rb

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def perform(req, options)
8282
:proxy_headers => @connection.proxy_response_headers,
8383
:connection => @connection,
8484
:encoding => options.encoding,
85-
:uri => req.uri,
8685
:request => req
8786
)
8887

lib/http/response.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class Response
4747
# @option opts [String] :uri
4848
def initialize(opts)
4949
@version = opts.fetch(:version)
50-
@uri = HTTP::URI.parse(opts.fetch(:uri)) if opts.include? :uri
50+
@request = opts.fetch(:request)
51+
@uri = HTTP::URI.parse(opts[:uri] || @request.uri)
5152
@status = HTTP::Response::Status.new(opts.fetch(:status))
5253
@headers = HTTP::Headers.coerce(opts[:headers] || {})
5354
@proxy_headers = HTTP::Headers.coerce(opts[:proxy_headers] || {})
54-
@request = opts.fetch(:request)
5555

5656
if opts.include?(:body)
5757
@body = opts.fetch(:body)

0 commit comments

Comments
 (0)