Skip to content

Custom headers erases all header defaults rather than merging the two #2862

@JoshMock

Description

@JoshMock

🐛 Bug report

When setting the headers config is set by during Client instantiation, those custom headers will erase any default header values that the library intends to keep set, rather than merging the defaults in with the custom ones.

To reproduce

Create a client with custom headers:

const client = new Client({
  headers: { 'x-custom-header': 'foobar' }.
  // other required options
})

When sending a request, we would expect to see the custom header as well as any default headers provided by the client, like user-agent:

{
  'user-agent': 'elasticsearch-js/...',
  'x-custom-header': 'foobar',
}

But instead you will see only the custom headers:

{
  'x-custom-header': 'foobar',
}

Expected behavior

Default headers should be merged with custom headers rather than be overwritten by them.

Node.js version

any

@elastic/elasticsearch version

8.x or newer

Operating system

any

Any other relevant environment information

elastic/kibana#222151 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions