Skip to content

Commit

Permalink
Support correct encoding parameter for HTTP.rb 2.x and earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
drcapulet committed Feb 11, 2020
1 parent 4256c29 commit db60b2d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/webmock/http_lib_adapters/http_rb/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ class << self
def from_webmock(webmock_response, request_signature = nil)
status = Status.new(webmock_response.status.first)
headers = webmock_response.headers || {}
body = Body.new(Streamer.new(webmock_response.body), encoding: webmock_response.body.encoding)
uri = normalize_uri(request_signature && request_signature.uri)

# HTTP.rb 3.0+ uses a keyword argument to pass the encoding, but 1.x
# and 2.x use a positional argument, and 0.x don't support supplying
# the encoding.
body = if HTTP::VERSION < "1.0.0"
Body.new(Streamer.new(webmock_response.body))
elsif HTTP::VERSION < "3.0.0"
Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
else
Body.new(Streamer.new(webmock_response.body), encoding: webmock_response.body.encoding)
end

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

new({
Expand Down

0 comments on commit db60b2d

Please sign in to comment.