Skip to content

Commit

Permalink
httpclient_adapter: use uri after filters when building req signature
Browse files Browse the repository at this point in the history
If a filter changes the URI (e.g. to enforce a protocol or change the
hostname of the request) this is currently unable to be mocked as
webmock fetches the URI for the signature of the request before calling
the filters!
  • Loading branch information
mattbnz committed Feb 13, 2024
1 parent 0e3c8fb commit 65ba375
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/webmock/http_lib_adapters/httpclient_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ def build_webmock_response(httpclient_response, body = nil)
end

def build_request_signature(req, reuse_existing = false)
uri = WebMock::Util::URI.heuristic_parse(req.header.request_uri.to_s)
uri.query = WebMock::Util::QueryMapper.values_to_query(req.header.request_query, notation: WebMock::Config.instance.query_values_notation) if req.header.request_query
uri.port = req.header.request_uri.port

@request_filter.each do |filter|
filter.filter_request(req)
end

uri = WebMock::Util::URI.heuristic_parse(req.header.request_uri.to_s)
uri.query = WebMock::Util::QueryMapper.values_to_query(req.header.request_query, notation: WebMock::Config.instance.query_values_notation) if req.header.request_query
uri.port = req.header.request_uri.port

headers = req.header.all.inject({}) do |hdrs, header|
hdrs[header[0]] ||= []
hdrs[header[0]] << header[1]
Expand Down

0 comments on commit 65ba375

Please sign in to comment.