Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure a custom User-Agent header is not overwritten #992

Merged
merged 2 commits into from
Aug 12, 2019

Conversation

philkra
Copy link
Contributor

@philkra philkra commented Aug 12, 2019

The PR is an enhancement to the comment of PR#991 and ensures that a custom user-agent header is not overwritten with the default value.

@@ -339,7 +339,8 @@ def perform_request(self, method, url, headers=None, params=None, body=None):

if headers is None:
headers = {}
headers["user-agent"] = "elasticsearch-py/%s (Python %s)" % (__versionstr__, python_version())
if "user-agent" not in headers:
headers["user-agent"] = "elasticsearch-py/%s (Python %s)" % (__versionstr__, python_version())
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we perhaps not do this at every request? I think this should follow the same exact logic as setting content-type at https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/connection/http_urllib3.py#L129 - done only once when instantiating the client and kept there as the default. Also all the headers will then be set in a single place.

Copy link
Contributor

@honzakral honzakral left a comment

Choose a reason for hiding this comment

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

thank you for the quick turnaround!

@philkra
Copy link
Contributor Author

philkra commented Aug 12, 2019

my pleasure :)

@honzakral honzakral merged commit 28920b5 into elastic:master Aug 12, 2019
@philkra philkra deleted the do-not-overwrite-user-agent branch August 12, 2019 12:24
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