module WebMock::NetHTTPUtility

def self.request_signature_from_request(net_http, request, body = nil)

def self.request_signature_from_request(net_http, request, body = nil)
  path = request.path
  if path.respond_to?(:request_uri) #https://github.com/bblimke/webmock/issues/288
    path = path.request_uri
  end
  path = WebMock::Util::URI.heuristic_parse(path).request_uri if path =~ /^http/
  uri = get_uri(net_http, path)
  method = request.method.downcase.to_sym
  headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}]
  if request.body_stream
    body = request.body_stream.read
    request.body_stream = nil
  end
  if body != nil && body.respond_to?(:read)
    request.set_body_internal body.read
  else
    request.set_body_internal body
  end
  WebMock::RequestSignature.new(method, uri, body: request.body, headers: headers)
end