webmock icon indicating copy to clipboard operation
webmock copied to clipboard

`WebMock::Util::Headers.normalize_headers` downcases characters in header keys

Open ulyssesrex opened this issue 6 years ago • 5 comments

This stub, chained with with(), will never match its intended request...

stub_request(:post, /urlmatcher/).
  with(headers: { 
    "SOAPAction" => "https://some.soap.endpoint/where/things/happen" 
  })

because the stub's HeadersPattern has been normalized and no longer matches the given header. Note Soapaction instead of SOAPAction.

#<WebMock::HeadersPattern:0x00007fe38db8b078                                                                                                             
     @pattern={"Soapaction"=>"https://www.assuresign.net/Services/DocumentNOW/Envelopes/IEnvelopeService/CreateEnvelope"}>

ulyssesrex avatar Nov 27 '19 03:11 ulyssesrex

@ulyssesrex thank you for pointing that. SOAPAction is indeed a culprit. I guess this can be changed in WebMock but with major version change in WebMock as I it would break many existing WebMock setups, where people set header expectations using e.g lowercase.

bblimke avatar Dec 27 '19 00:12 bblimke

The normalized form of headers which is enforced by HTTP/2 is lowercase.

ioquatix avatar Jan 06 '20 00:01 ioquatix

Thank you for the input @ioquatix It's only for HTTP/2 right?

bblimke avatar Jan 06 '20 22:01 bblimke

It's also for HTTP/1.

https://stackoverflow.com/questions/5258977/are-http-headers-case-sensitive

HTTP/2 just makes it an error and servers will drop the connection.

ioquatix avatar Jan 06 '20 22:01 ioquatix

Just FYI, this will become standard rack behaviour too: https://github.com/rack/rack/issues/1592

ioquatix avatar Feb 24 '20 06:02 ioquatix