pact-foundation/pact-provider-verifier

HTTP Headers with periods (`.`) are ignored

fjukstad opened this issue · 4 comments

Hi,

I am trying to verify a Pact where some of the requests require HTTP headers with . characters. From inspecting the packets in Wireshark it looks as if the pact-provider-verifier is ignoring HTTP headers with .. From RFC 7230 it looks as if . are valid characters and should be included. I expect that all headers with valid characters are included in the requests that are replayed. I saw that there was a similar issue in the pact-net repo but regarding _ characters. I'm using pact-provider-verifier version 1.28.0.

Here is an example pact, and below is a screenshot from Wireshark when running pact-provider-verifier.

{
  "consumer": {
    "name": "Consumer"
  },
  "provider": {
    "name": "TestProvider"
  },
  "interactions": [
    {
      "description": "A POST with some illegal HTTP Headers",
      "request": {
        "method": "post",
        "path": "/",
        "headers": {
          "ThisHeaderIsOk": "value",
          "This_Header_Is_Also_Ok": "value",
          "But.This.Header.Is.Not.Ok": "value"
        },
        "body": {
	}
      },
      "response": {
        "status": 200,
        "headers": {
        },
        "body": {
	}
      },
      "metadata": null
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}

image

Any suggestions on how to get HTTP headers with . added to the requests?

Doing some debugging. When running the Ruby code directly, I can see the header:

I, [2020-02-12T08:18:11.992539 #49620]  INFO -- : Sending GET request to path: "/thing" with headers: {"HTTP_ACCEPT"=>"application/json", "HTTP_FOO.BAR"=>"foobar"}, see debug logs for body

When running the pact-provider-verifier, the header with the . goes missing.

"headers": { "Foo.Bar": "foobar", "Foobar": "meep"},

and I only get "HTTP_FOOBAR"=>"meep" in the logs. I suspect it's something to do with the rack reverse proxy gem. I'll keep digging.

Ok, so the culprit is a line in the rack-proxy gem.

def extract_http_request_headers(env)
  headers = env.reject do |k, v|
    !(/^HTTP_[A-Z0-9_]+$/ === k) || v.nil?
  end
  ...
end

That regular expression should be /^HTTP_[A-Z0-9_\.]+$/. I don't know how much luck I'll have submitting a PR to such a widely used gem, but I'll give it a go. As a fallback, we may have to do some naughty monkey patching.

PR raised here ncr/rack-proxy#87

Great! Thanks for your help and submitting a PR, hopefully we'll get it merged!