Skip to content

Caseless header comparison in the HTTP adapter #2876

@mastermatt

Description

@mastermatt

Describe the bug
The HTTP adapter does not use caseless comparison before overriding the User-Agent header or deleting the Authorization header.

It also overwrites any provided Content-Length header.

To Reproduce

axios({
  method: 'post',
  url: 'https://postman-echo.com/post',
  auth: {
    username: 'janedoe',
    password: 's00pers3cret'
  },
  headers: {
    authorization: 'foo',
    'Content-Length': 10,
    'User-agent': 'bar'
  },
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
})  
.then(function (response) {
  console.log(response.data);
})
.catch(function (error) {
  console.log(error);
});


> { args: {},
  data: { firstName: 'Fred', lastName: 'Flintstone' },
  files: {},
  form: {},
  headers:
   { 'x-forwarded-proto': 'https',
     host: 'postman-echo.com',
     'content-length': '44',
     accept: 'application/json, text/plain, */*',
     authorization: 'foo',
     'content-type': 'application/json;charset=utf-8',
     'user-agent': 'axios/0.18.1',
     'x-forwarded-port': '443' },
  json: { firstName: 'Fred', lastName: 'Flintstone' },
  url: 'https://postman-echo.com/post' }

Expected behavior
The server should have received the following headers

     'x-forwarded-proto': 'https',
     host: 'postman-echo.com',
     'content-length': '10', // not '44'
     accept: 'application/json, text/plain, */*',
     authorization: 'Basic amFuZWRvZTpzMDBwZXJzM2NyZXQ=', // not 'foo'
     'content-type': 'application/json;charset=utf-8',
     'user-agent': 'bar', // not 'axios/0.18.1'
     'x-forwarded-port': '443'

I have a PR ready, but saw you prefer an issue be created first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions