Disable header case check when running tests

** (Plug.Conn.WrapperError) ** (Plug.Conn.InvalidHeaderError) header key is not lowercase: "X-AlchemyAPI-Error-Msg"

I really need to be able to disable that check during testing. It’s a problem when maintaining strict compatibility with an existing legacy API.

(I know that headers are specified to be case-insensitive. But I also know that given thousands of users of an API, there is certain to be erroneous code in production which performs case-sensitive comparisons.)

I don’t think it is possible to disable the check today so please open up an issue in Plug (or send a PR). :slight_smile:

I’d be happy to submit a PR if I could have a pointer as to where to start & a suggestion as to how this option should be specified.

The check happens around here: https://github.com/elixir-lang/plug/blob/master/lib/plug/conn.ex#L1012-L1020

The best idea is probably to store if you want to check or not in the second element of that tuple. The configuration should probably be specified when you create a connection on Plug.Test.conn.

Is this still a good idea to have the option to disable header case checking in the tests? It has been like 3 years since the last comment in this thread.

It can be done throw configuration (for example in config.exs file):

config :plug,
  validate_header_keys_during_test: :false
4 Likes