Skip to content

Avoid duplicated content-type headers#2962

Open
picandocodigo wants to merge 1 commit into
mainfrom
content_type
Open

Avoid duplicated content-type headers#2962
picandocodigo wants to merge 1 commit into
mainfrom
content_type

Conversation

@picandocodigo
Copy link
Copy Markdown
Member

Adds tests for Manticore, depends on changes in transport: elastic/elastic-transport-ruby#115

Addresses #2961

@picandocodigo picandocodigo requested a review from mashhurs May 28, 2026 15:22
Adds tests for Manticore, depends on changes in transport:
elastic/elastic-transport-ruby#115

Addresses #2961
Copy link
Copy Markdown
Member Author

@picandocodigo picandocodigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests for JRuby will pass after we release elastic/elastic-transport-ruby#115

Copy link
Copy Markdown

@mashhurs mashhurs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main logics LGTM!
Left a suggestion to fix the unit test. Another out of scope suggestion, it looks like we can create a shared test and use for each duplicate header check specs. It is up to you to make it now or in the future.

headers['content-type'] = 'application/vnd.elasticsearch+json; compatible-with=9'
end
unless user_headers&.keys&.detect { |h| h =~ /accept/ }
unless user_headers&.keys&.detect { |h| h =~ /accept/i }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Comment on lines +166 to +167
expect(connection_headers['content-type']).to be nil
expect(connection_headers.fetch('Content-Type')).to eq 'application/text'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this should be reverse since we are setting content-type

Suggested change
expect(connection_headers['content-type']).to be nil
expect(connection_headers.fetch('Content-Type')).to eq 'application/text'
expect(connection_headers['Content-Type']).to be nil
expect(connection_headers.fetch('content-type')).to eq 'application/text'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being set at the transport level in manticore.rb. On initialize of the base class, it runs build_connections which calls apply_headers (the code I updated in the other PR).

The code eventually sets headers[CONTENT_TYPE_STRING], and CONTENT_TYPE_STR is 'Content-Type'. So the final key that will be sent to Elasticsearch will be Content-Type, no matter how it's set on the elasticsearch-ruby side. I wrote tests for setting content-type and Content-Type and making sure only Content-Type is used in the request with Manticore. I will also add tests on the transport side.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you for explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants