Skip to content

Commit 2fb5e6f

Browse files
authored
Use Request#uri in Response (#569)
* 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
1 parent 0b51aa7 commit 2fb5e6f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
Fix HTTP parser.
1818
([@ixti], [@fxposter])
1919

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

2126
## 4.1.1 (2019-03-12)
2227

@@ -793,3 +798,4 @@ end
793798
[@RickCSong]: https://github.com/RickCSong
794799
[@fxposter]: https://github.com/fxposter
795800
[@mamoonraja]: https://github.com/mamoonraja
801+
[@joshuaflanagan]: https://github.com/joshuaflanagan

lib/http/response.rb

+10-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
require "http/mime_type"
88
require "http/response/status"
99
require "http/response/inflater"
10-
require "http/uri"
1110
require "http/cookie_jar"
1211
require "time"
1312

@@ -26,9 +25,6 @@ class Response
2625
# @return [Body]
2726
attr_reader :body
2827

29-
# @return [URI, nil]
30-
attr_reader :uri
31-
3228
# @return [Request]
3329
attr_reader :request
3430

@@ -44,11 +40,10 @@ class Response
4440
# @option opts [HTTP::Connection] :connection
4541
# @option opts [String] :encoding Encoding to use when reading body
4642
# @option opts [String] :body
47-
# @option opts [String] :uri
43+
# @option opts [HTTP::Request] request
4844
def initialize(opts)
4945
@version = opts.fetch(:version)
5046
@request = opts.fetch(:request)
51-
@uri = HTTP::URI.parse(opts[:uri] || @request.uri)
5247
@status = HTTP::Response::Status.new(opts.fetch(:status))
5348
@headers = HTTP::Headers.coerce(opts[:headers] || {})
5449
@proxy_headers = HTTP::Headers.coerce(opts[:proxy_headers] || {})
@@ -65,24 +60,28 @@ def initialize(opts)
6560

6661
# @!method reason
6762
# @return (see HTTP::Response::Status#reason)
68-
def_delegator :status, :reason
63+
def_delegator :@status, :reason
6964

7065
# @!method code
7166
# @return (see HTTP::Response::Status#code)
72-
def_delegator :status, :code
67+
def_delegator :@status, :code
7368

7469
# @!method to_s
7570
# (see HTTP::Response::Body#to_s)
76-
def_delegator :body, :to_s
71+
def_delegator :@body, :to_s
7772
alias to_str to_s
7873

7974
# @!method readpartial
8075
# (see HTTP::Response::Body#readpartial)
81-
def_delegator :body, :readpartial
76+
def_delegator :@body, :readpartial
8277

8378
# @!method connection
8479
# (see HTTP::Response::Body#connection)
85-
def_delegator :body, :connection
80+
def_delegator :@body, :connection
81+
82+
# @!method uri
83+
# @return (see HTTP::Request#uri)
84+
def_delegator :@request, :uri
8685

8786
# Returns an Array ala Rack: `[status, headers, body]`
8887
#

0 commit comments

Comments
 (0)