Skip to content

Commit

Permalink
Response#uri can be set directly, or pulled from the Request
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshuaflanagan committed Oct 20, 2019
1 parent 5bb01ce commit 236695b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/http/client.rb
Expand Up @@ -82,7 +82,6 @@ def perform(req, options)
:proxy_headers => @connection.proxy_response_headers,
:connection => @connection,
:encoding => options.encoding,
:uri => req.uri,
:request => req
)

Expand Down
4 changes: 2 additions & 2 deletions lib/http/response.rb
Expand Up @@ -47,11 +47,11 @@ class Response
# @option opts [String] :uri
def initialize(opts)
@version = opts.fetch(:version)
@uri = HTTP::URI.parse(opts.fetch(:uri)) if opts.include? :uri
@request = opts.fetch(:request)
@uri = HTTP::URI.parse(opts[:uri] || @request.uri)
@status = HTTP::Response::Status.new(opts.fetch(:status))
@headers = HTTP::Headers.coerce(opts[:headers] || {})
@proxy_headers = HTTP::Headers.coerce(opts[:proxy_headers] || {})
@request = opts.fetch(:request)

if opts.include?(:body)
@body = opts.fetch(:body)
Expand Down

0 comments on commit 236695b

Please sign in to comment.