Skip to content

Commit

Permalink
Merge pull request #391 from nylas/johnjjung/gzip
Browse files Browse the repository at this point in the history
adding this header reduces the networking by 10X
  • Loading branch information
johnjjung authored Oct 18, 2024
2 parents 220cc27 + 556a30f commit 3ebb704
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions nylas/handler/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/handler/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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",
},
}

Expand All @@ -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",
},
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit 3ebb704

Please sign in to comment.