Skip to content

Commit

Permalink
Use Request#uri in Response
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ixti committed Oct 21, 2019
1 parent 0b51aa7 commit 8370f71
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/http/response.rb
Expand Up @@ -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"

Expand All @@ -26,9 +25,6 @@ class Response
# @return [Body]
attr_reader :body

# @return [URI, nil]
attr_reader :uri

# @return [Request]
attr_reader :request

Expand All @@ -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] || {})
Expand All @@ -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]`
#
Expand Down

0 comments on commit 8370f71

Please sign in to comment.