axios-mock-adapter icon indicating copy to clipboard operation
axios-mock-adapter copied to clipboard

Disallow upper-case characters in mocked headers

Open nip3o opened this issue 6 years ago • 0 comments

The Response section of the Axios README contains a subtle detail:

// headers the headers that the server responded with // All header names are lower cased

This behavior recently bit me after migrating from another HTTP lib – the property used to be accessible as headers.Date, but after migrating to Axios the property was instead accessible as headers.date. Our tests didn't discover it since they looked something like this:

mockedAxios.onGet("/some-url/").reply(200, "", { Date: "2019-01-01" })

Since headers are always lowercase when accessing them with Axios, it should be an error to create a mock response with non-lowercase header names. Alternatively, mock adapter should lower-case them automatically, but I feel that might be harder to debug.

I'm happy to contribute with a PR, just want a second opinion first.

nip3o avatar Mar 22 '19 21:03 nip3o