Skip to content

Header copying issue with version 3.3.15 #2001

@Kostersson

Description

@Kostersson

Hi!

Version 3.3.15 introduced a bug, when copying headers. Here is a minimum project example that causes the issue.
https://github.com/Kostersson/aws4-axios-headers-bug

The issue is that when copying axios headers, axios concatenates all current headers into a single header name, which causes its value to be undefined, like so:

 Object [AxiosHeaders] {
    'Accept: application/json, text/plain, */*\nContent-Type: application/json': undefined
 }

I was not able to reproduce the same behaviour by adding following test to axiosInterceptor.test.ts

  it("should copy headers correctly", async () => {
    // Arrange
    const client = axios.create()

    client.interceptors.request.use(
      aws4Interceptor({options: {region: "local"}, instance: axios}),
    )

    const url = "http://localhost/foo"
    const config = {
      headers: {
        Accept: 'application/json, text/plain, */*',
        'Content-Type': 'application/json'
      }
    }

    // setup nock to return a
    nock(url)
      .post("")
      .reply(500)


    // Act
    await client.post(url, '', config)
      .catch(e => {
        // Assert
        expect(JSON.stringify(e.config['_originalHeaders'])).toBe(
          JSON.stringify({
            Accept: 'application/json, text/plain, */*',
            'Content-Type': 'application/json'
          }))
      })
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions