From 5ed3ab2da9696c92aad4494ff8bf668050379c80 Mon Sep 17 00:00:00 2001 From: John Jung Date: Fri, 18 Oct 2024 13:42:44 -0400 Subject: [PATCH 1/2] adding this header reduces the networking by 10X --- nylas/handler/http_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nylas/handler/http_client.py b/nylas/handler/http_client.py index 5b1d77a..ee29665 100644 --- a/nylas/handler/http_client.py +++ b/nylas/handler/http_client.py @@ -179,6 +179,7 @@ def _build_headers( "X-Nylas-API-Wrapper": "python", "User-Agent": user_agent_header, "Authorization": f"Bearer {api_key}", + "Accept-Encoding": "gzip", } if data is not None and data.content_type is not None: headers["Content-type"] = data.content_type From 556a30f2cc8ff53298c5723a636aedd1c9aebf58 Mon Sep 17 00:00:00 2001 From: John Jung Date: Fri, 18 Oct 2024 13:48:55 -0400 Subject: [PATCH 2/2] fix tests --- tests/handler/test_http_client.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/handler/test_http_client.py b/tests/handler/test_http_client.py index e6a6157..4f5cd98 100644 --- a/tests/handler/test_http_client.py +++ b/tests/handler/test_http_client.py @@ -34,6 +34,7 @@ def test_build_headers_default(self, http_client, patched_version_and_sys): "X-Nylas-API-Wrapper": "python", "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", + "Accept-Encoding": "gzip", } def test_build_headers_extra_headers(self, http_client, patched_version_and_sys): @@ -50,6 +51,7 @@ def test_build_headers_extra_headers(self, http_client, patched_version_and_sys) "Authorization": "Bearer test-key", "foo": "bar", "X-Test": "test", + "Accept-Encoding": "gzip", } def test_build_headers_json_body(self, http_client, patched_version_and_sys): @@ -64,6 +66,7 @@ def test_build_headers_json_body(self, http_client, patched_version_and_sys): "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", "Content-type": "application/json", + "Accept-Encoding": "gzip", } def test_build_headers_form_body(self, http_client, patched_version_and_sys): @@ -79,6 +82,7 @@ def test_build_headers_form_body(self, http_client, patched_version_and_sys): "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", "Content-type": "application/x-www-form-urlencoded", + "Accept-Encoding": "gzip", } def test_build_headers_override_headers(self, http_client, patched_version_and_sys): @@ -97,6 +101,7 @@ def test_build_headers_override_headers(self, http_client, patched_version_and_s "Authorization": "Bearer test-key", "foo": "bar", "X-Test": "test", + "Accept-Encoding": "gzip", } def test_build_headers_override_api_key(self, http_client, patched_version_and_sys): @@ -110,6 +115,7 @@ def test_build_headers_override_api_key(self, http_client, patched_version_and_s "X-Nylas-API-Wrapper": "python", "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key-override", + "Accept-Encoding": "gzip", } def test_build_request_default(self, http_client, patched_version_and_sys): @@ -125,6 +131,7 @@ def test_build_request_default(self, http_client, patched_version_and_sys): "X-Nylas-API-Wrapper": "python", "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", + "Accept-Encoding": "gzip", }, } @@ -144,6 +151,7 @@ def test_build_request_override_api_uri(self, http_client, patched_version_and_s "X-Nylas-API-Wrapper": "python", "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", + "Accept-Encoding": "gzip", }, } @@ -201,6 +209,7 @@ def test_execute_download_request_override_timeout( "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", "Content-type": "application/json", + "Accept-Encoding": "gzip", }, timeout=60, stream=False, @@ -291,6 +300,7 @@ def test_execute(self, http_client, patched_version_and_sys, patched_request): "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", "Content-type": "application/json", + "Accept-Encoding": "gzip", "test": "header", }, json={"foo": "bar"}, @@ -319,6 +329,7 @@ def test_execute_override_timeout( "User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3", "Authorization": "Bearer test-key", "Content-type": "application/json", + "Accept-Encoding": "gzip", "test": "header", }, json={"foo": "bar"},