8000 Switching back to gzip for the headers. · KEClaytor/influxdb-python@d8ad79e · GitHub
[go: up one dir, main page]

Skip to content

Commit d8ad79e

Browse files
author
Kevin Claytor
committed
Switching back to gzip for the headers.
1 parent 2f813d0 commit d8ad79e

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

influxdb/client.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import time
1010
import random
1111

12-
import zlib
12+
import gzip
1313
import json
1414
import socket
1515
import requests
@@ -151,14 +151,6 @@ def __init__(self,
151151
}
152152

153153
self._gzip = gzip
154-
if self._gzip:
155-
# Create the zlib compression object to do the compression later.
156-
# We need the gzip headers which is done with "zlib.MAX_WBITS | 16"
157-
self._gzip_compressor = zlib.compressobj(
158-
9,
159-
zlib.DEFLATED,
160-
zlib.MAX_WBITS | 16
161-
)
162154

163155
@property
164156
def _baseurl(self):
@@ -281,12 +273,15 @@ def request(self, url, method='GET', params=None, data=None,
281273

282274
if self._gzip:
283275
# Allow us to receive gzip'd data (requests will decompress)
276+
# as well as write it out
284277
headers.update({
285278
'Accept-Encoding': 'gzip',
286279
'Content-Encoding': 'gzip',
287280
})
281+
# Note you may get better performance with zlib (speed, ratio)
282+
# but the headers are such that Influx rejects them.
288283
if data is not None:
289-
data = self._gzip_compressor.compress(data)
284+
data = gzip.compress(data, compresslevel=9)
290285

291286
# Try to send the request more than once by default (see #103)
292287
retry = True

influxdb/tests/client_test.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import unittest
2525
import warnings
2626

27-
import zlib
27+
import gzip
2828
import json
2929
import mock
3030
import requests
@@ -235,14 +235,9 @@ def test_write_gzip(self):
235235
"fields": {"value": 0.64}}]}
236236
)
237237

238-
gzip_compressor = zlib.compressobj(
239-
9,
240-
zlib.DEFLATED,
241-
zlib.MAX_WBITS | 16
242-
)
243238
self.assertEqual(
244239
m.last_request.body,
245-
gzip_compressor.compress(
240+
gzip.compress(
246241
b"cpu_load_short,host=server01,region=us-west "
247242
b"value=0.64 1257894000000000000\n"
248243
),
@@ -262,14 +257,9 @@ def test_write_points_gzip(self):
262257
self.dummy_points,
263258
)
264259

265-
gzip_compressor = zlib.compressobj(
266-
9,
267-
zlib.DEFLATED,
268-
zlib.MAX_WBITS | 16
269-
)
270260
self.assertEqual(
271261
m.last_request.body,
272-
gzip_compressor.compress(
262+
gzip.compress(
273263
b'cpu_load_short,host=server01,region=us-west '
274264
b'value=0.64 1257894000123456000\n'
275265
),

influxdb/tests/server_tests/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,17 @@ class SingleTestCaseWithServerGzipMixin(object):
107107
gzip=True
108108
"""
109109

110-
tearDown = _teardown_influxdb_server
111-
112110
@classmethod
113111
def setUp(cls):
114112
"""Set up an instance of the SingleTestCaseWithServerGzipMixin."""
115113
_setup_influxdb_server(cls)
116114
_setup_gzip_client(cls)
117115

116+
@classmethod
117+
def tearDown(cls):
118+
"""Tear down an instance of the SingleTestCaseWithServerMixin."""
119+
_teardown_influxdb_server(cls)
120+
118121

119122
class ManyTestCasesWithServerGzipMixin(object):
120123
"""Define the many testcase with server with gzip client mixin.
@@ -128,3 +131,8 @@ def setUpClass(cls):
128131
"""Set up an instance of the ManyTestCasesWithServerGzipMixin."""
129132
_setup_influxdb_server(cls)
130133
_setup_gzip_client(cls)
134+
135+
@classmethod
136+
def tearDown(cls):
137+
"""Tear down an instance of the SingleTestCaseWithServerMixin."""
138+
_teardown_influxdb_server(cls)

0 commit comments

Comments
 (0)
0