Skip to content

Commit

Permalink
Merge pull request #1050 from mkmba-nz/webmock_sig_uri_after_filters
Browse files Browse the repository at this point in the history
httpclient_adapter: use uri after filters when building request signature
  • Loading branch information
bblimke committed Feb 19, 2024
2 parents 37c9de9 + 96726c0 commit ea7792c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/webmock/http_lib_adapters/httpclient_adapter.rb
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
5 changes: 4 additions & 1 deletion spec/acceptance/httpclient/httpclient_spec.rb
Expand Up @@ -102,6 +102,7 @@
class Filter
def filter_request(request)
request.header["Authorization"] = "Bearer 0123456789"
request.header.request_uri.query = "webmock=here"
end

def filter_response(request, response)
Expand All @@ -112,7 +113,9 @@ def filter_response(request, response)
before do
@client = HTTPClient.new
@client.request_filter << Filter.new
stub_request(:get, 'www.example.com').with(headers: {'Authorization' => 'Bearer 0123456789'})
stub_request(:get, 'www.example.com').with(
query: {'webmock' => 'here'},
headers: {'Authorization' => 'Bearer 0123456789'})
end

it "supports request filters" do
Expand Down

0 comments on commit ea7792c

Please sign in to comment.