From 8370f710a725e9581dd1927d360c7bf0df0f1873 Mon Sep 17 00:00:00 2001 From: Alexey Zapparov Date: Mon, 21 Oct 2019 23:20:46 +0200 Subject: [PATCH] Use Request#uri in Response Response initialize requires Request object now, making uri parsing absolutely redundant. And as it's a breaking change anyway - we should get rid of `:uri` option completely. NOTE: We need to update WebMock's adapter to reflect this change prior releasing v5.0.0 --- lib/http/response.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/http/response.rb b/lib/http/response.rb index 6527b2bc..9f0d1f35 100644 --- a/lib/http/response.rb +++ b/lib/http/response.rb @@ -7,7 +7,6 @@ require "http/mime_type" require "http/response/status" require "http/response/inflater" -require "http/uri" require "http/cookie_jar" require "time" @@ -26,9 +25,6 @@ class Response # @return [Body] attr_reader :body - # @return [URI, nil] - attr_reader :uri - # @return [Request] attr_reader :request @@ -44,11 +40,10 @@ class Response # @option opts [HTTP::Connection] :connection # @option opts [String] :encoding Encoding to use when reading body # @option opts [String] :body - # @option opts [String] :uri + # @option opts [HTTP::Request] request def initialize(opts) @version = opts.fetch(:version) @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] || {}) @@ -65,24 +60,28 @@ def initialize(opts) # @!method reason # @return (see HTTP::Response::Status#reason) - def_delegator :status, :reason + def_delegator :@status, :reason # @!method code # @return (see HTTP::Response::Status#code) - def_delegator :status, :code + def_delegator :@status, :code # @!method to_s # (see HTTP::Response::Body#to_s) - def_delegator :body, :to_s + def_delegator :@body, :to_s alias to_str to_s # @!method readpartial # (see HTTP::Response::Body#readpartial) - def_delegator :body, :readpartial + def_delegator :@body, :readpartial # @!method connection # (see HTTP::Response::Body#connection) - def_delegator :body, :connection + def_delegator :@body, :connection + + # @!method uri + # @return (see HTTP::Request#uri) + def_delegator :@request, :uri # Returns an Array ala Rack: `[status, headers, body]` #