From 4430932bacefc28d211cee3c5798ade17b8a8add Mon Sep 17 00:00:00 2001 From: Joshua Flanagan Date: Wed, 24 Apr 2019 18:01:20 -0500 Subject: [PATCH] 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. --- lib/http/client.rb | 1 - lib/http/response.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/http/client.rb b/lib/http/client.rb index 91ac8409..daca1c23 100644 --- a/lib/http/client.rb +++ b/lib/http/client.rb @@ -82,7 +82,6 @@ def perform(req, options) :proxy_headers => @connection.proxy_response_headers, :connection => @connection, :encoding => options.encoding, - :uri => req.uri, :request => req ) diff --git a/lib/http/response.rb b/lib/http/response.rb index 8b86df05..6527b2bc 100644 --- a/lib/http/response.rb +++ b/lib/http/response.rb @@ -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)