diff --git a/lib/webmock/http_lib_adapters/net_http.rb b/lib/webmock/http_lib_adapters/net_http.rb index fd2a4a6f..e8c8cdce 100644 --- a/lib/webmock/http_lib_adapters/net_http.rb +++ b/lib/webmock/http_lib_adapters/net_http.rb @@ -257,6 +257,10 @@ def self.request_signature_from_request(net_http, request, body = nil) headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}] + # Prevent empty Host header by providing similar behavior as Net::HTTP + # https://github.com/ruby/net-http/blob/cfbbb50c931a78fc2b5c731b9abeda161e1dfdd1/lib/net/http.rb#L2482 + headers['host'] = URI(uri).host if headers['host'].nil? + if request.body_stream body = request.body_stream.read request.body_stream = nil