Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

If http_compress is passed, request is compressed using gzip. #73

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion elasticsearch_async/connection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gzip
import asyncio
import ssl
import warnings
Expand All @@ -16,7 +17,7 @@ class AIOHttpConnection(Connection):
def __init__(self, host='localhost', port=9200, http_auth=None,
use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None,
client_key=None, loop=None, use_dns_cache=True, headers=None,
ssl_context=None, **kwargs):
ssl_context=None, http_compress=False, **kwargs):
super().__init__(host=host, port=port, **kwargs)

self.loop = asyncio.get_event_loop() if loop is None else loop
Expand All @@ -28,8 +29,11 @@ def __init__(self, host='localhost', port=9200, http_auth=None,
if isinstance(http_auth, (tuple, list)):
http_auth = aiohttp.BasicAuth(*http_auth)

self.http_compress = http_compress
headers = headers or {}
headers.setdefault('content-type', 'application/json')
if self.http_compress:
headers.update({'content-encoding': 'gzip', 'accept-encoding': 'gzip,deflate'})

# if providing an SSL context, raise error if any other SSL related flag is used
if ssl_context and (verify_certs or ca_certs):
Expand Down Expand Up @@ -91,6 +95,9 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
url_path = '%s?%s' % (url, urlencode(params or {}))
url = self.base_url + url_path

if self.http_compress and body:
body = gzip.compress(body)

start = self.loop.time()
response = None
try:
Expand Down