Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Headers with periods (.) are ignored #50

Closed
fjukstad opened this issue Feb 11, 2020 · 4 comments
Closed

HTTP Headers with periods (.) are ignored #50

fjukstad opened this issue Feb 11, 2020 · 4 comments

Comments

@fjukstad
Copy link

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?

@bethesque
Copy link
Member

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.

@bethesque
Copy link
Member

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.

@bethesque
Copy link
Member

PR raised here ncr/rack-proxy#87

@fjukstad
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants