add default content type for empty requests #275
Open
margaretjgu wants to merge 1 commit intomainfrom
Open
Conversation
margaretjgu
commented
Feb 16, 2026
| + resolve_default(client_meta, ()) | ||
| ) | ||
|
|
||
| request_headers.setdefault("content-type", "application/json") |
Member
Author
There was a problem hiding this comment.
generated apis already set content-type: application/json or x-ndjson for e.g. bulk requests before calling transport.
so setdefault is a no-op in this case, so the predefined content-type is preserved.
eg. bulk request in client where content-type is always set
https://github.com/elastic/elasticsearch-py/blob/c485ee48177892efd8083553ebf14bfaa804e59b/elasticsearch/_sync/client/__init__.py#L749-L752
e.g. where content-type is optionally set if body is present like search
https://github.com/elastic/elasticsearch-py/blob/f59037ee0e9de82719dce6ba8b56b9022d60ee0c/elasticsearch/_sync/client/watcher.py#L337-L341
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes elastic/elasticsearch-py#3305
Elasticsearch 9.1+ will request requests with no content-types.
Python transport layer only includes content-type when a request body is present but bodyless requests will have no content-type.
Bodyless requests will now get
application/jsonas default