From cf383e32cf901fcad429f9a5d5e8fda0a33bc1df Mon Sep 17 00:00:00 2001 From: Kaushil Kundalia <39802957+kaushil24@users.noreply.github.com> Date: Sat, 30 Apr 2022 10:26:39 +0000 Subject: [PATCH 1/2] passing default flag to toggle global request update while making request by default if you pass request_headers while making a call; it will update the clients request header. To prevent this; you can use this flag --- python_http_client/client.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/python_http_client/client.py b/python_http_client/client.py index 3a56235..3351f64 100644 --- a/python_http_client/client.py +++ b/python_http_client/client.py @@ -224,42 +224,48 @@ def http_request( query_params=None, request_headers=None, timeout=None, + global_update_request_headers=True, **_): """Make the API call :param timeout: HTTP request timeout. Will be propagated to urllib client :type timeout: float :param request_headers: HTTP headers. Will be merged into - current client object state + current client object state only if global_update_request_headers + set `True` :type request_headers: dict :param query_params: HTTP query parameters :type query_params: dict :param request_body: HTTP request body :type request_body: string or json-serializable object + :param global_update_request_headers: Update client object request_headers state if + set `True`. Default `True`. If set `False` the request_header passed will be use + only for that request :param kwargs: :return: Response object """ - if request_headers: + if request_headers and not global_update_request_headers: self._update_headers(request_headers) + request_headers = self.request_headers if request_body is None: data = None else: # Don't serialize to a JSON formatted str # if we don't have a JSON Content-Type - if 'Content-Type' in self.request_headers and \ - self.request_headers['Content-Type'] != \ + if 'Content-Type' in request_headers and \ + request_headers['Content-Type'] != \ 'application/json': data = request_body.encode('utf-8') else: - self.request_headers.setdefault( + request_headers.setdefault( 'Content-Type', 'application/json') data = json.dumps(request_body).encode('utf-8') opener = urllib.build_opener() request = urllib.Request( self._build_url(query_params), - headers=self.request_headers, + headers=request_headers if global_update_request_headers else request_headers, data=data, ) request.get_method = lambda: method From 3f79757bdf64da61c45f37c12dfc5bd08238fb0b Mon Sep 17 00:00:00 2001 From: Kaushil Kundalia <39802957+kaushil24@users.noreply.github.com> Date: Sat, 30 Apr 2022 10:38:48 +0000 Subject: [PATCH 2/2] version update, changelog update and setup base_url update --- CHANGELOG.md | 5 +++++ VERSION.txt | 2 +- setup.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90bd3da..314dd05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +[2022-04-30] Version 3.3.8 +-------------------------- +**Library - Chore** +- Passing `global_update_request_headers` flag to toggle original client's request_headers update. + [2022-03-09] Version 3.3.7 -------------------------- diff --git a/VERSION.txt b/VERSION.txt index 86fb650..37d02a6 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.3.7 +3.3.8 diff --git a/setup.py b/setup.py index aedd67c..106fa5c 100755 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ with io.open(version_path, encoding='utf-8') as version_file: version = version_file.read().strip() -base_url = 'https://github.com/sendgrid/' +base_url = 'https://github.com/kaushil24/' copy_file(version_path, os.path.join(dir_path, 'python_http_client', 'VERSION.txt'),