Skip to content

Commit

Permalink
Use Request#uri in Response (#569)
Browse files Browse the repository at this point in the history
* 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

* Update Changelog with #546 changes

SEE ALSO
--------

ShippingEasy/webmock@505ad00
  • Loading branch information
ixti committed Oct 21, 2019
1 parent 0b51aa7 commit 2fb5e6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Expand Up @@ -17,6 +17,11 @@
Fix HTTP parser.
([@ixti], [@fxposter])

* [#546](https://github.com/httprb/http/pull/546)
**BREAKING CHANGE**
Provide initiating `HTTP::Request` object on `HTTP::Response`.
([@joshuaflanagan])


## 4.1.1 (2019-03-12)

Expand Down Expand Up @@ -793,3 +798,4 @@ end
[@RickCSong]: https://github.com/RickCSong
[@fxposter]: https://github.com/fxposter
[@mamoonraja]: https://github.com/mamoonraja
[@joshuaflanagan]: https://github.com/joshuaflanagan
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 2fb5e6f

Please sign in to comment.