Skip to content

Commit

Permalink
Merge pull request #941 from horgh/horgh/http-rb-5
Browse files Browse the repository at this point in the history
Support http.rb 5.x
  • Loading branch information
bblimke authored May 14, 2021
2 parents ab85203 + 3e81062 commit 5e011c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lib/webmock/http_lib_adapters/http_rb/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def to_webmock
end

class << self
def from_webmock(webmock_response, request_signature = nil)
def from_webmock(request, webmock_response, request_signature = nil)
status = Status.new(webmock_response.status.first)
headers = webmock_response.headers || {}
uri = normalize_uri(request_signature && request_signature.uri)
Expand All @@ -29,12 +29,23 @@ def from_webmock(webmock_response, request_signature = nil)

return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"

# 5.0.0 had a breaking change to require request instead of uri.
if HTTP::VERSION < '5.0.0'
return new({
status: status,
version: "1.1",
headers: headers,
body: body,
uri: uri
})
end

new({
status: status,
version: "1.1",
headers: headers,
body: body,
uri: uri
request: request,
})
end

Expand Down
2 changes: 1 addition & 1 deletion lib/webmock/http_lib_adapters/http_rb/webmock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def replay
webmock_response.raise_error_if_any

invoke_callbacks(webmock_response, real_request: false)
::HTTP::Response.from_webmock webmock_response, request_signature
::HTTP::Response.from_webmock @request, webmock_response, request_signature
end

def raise_timeout_error
Expand Down

0 comments on commit 5e011c8

Please sign in to comment.