Skip to content

Commit

Permalink
chore: Compress (gzip) request if server support it
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykGala committed Sep 29, 2023
1 parent 5c8bed3 commit a57aa7e
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/neptune/internal/backends/hosted_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@


class GzipAdapter(HTTPAdapter):
_COMPRESSION_LEVEL = int((zlib.Z_BEST_SPEED + zlib.Z_BEST_COMPRESSION) / 2)

def send(self, request, stream=False, **kw):
if request.body is not None and not stream:
request_body = request.body if isinstance(request.body, bytes) else bytes(request.body, "utf-8")
gzip_compress = zlib.compressobj(GzipAdapter._COMPRESSION_LEVEL, zlib.DEFLATED, zlib.MAX_WBITS | 16)
gzip_compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, zlib.MAX_WBITS | 16)
compressed = gzip_compress.compress(request_body) + gzip_compress.flush()
request.prepare_body(compressed, None)
request.headers["Content-Encoding"] = "gzip"
Expand Down

0 comments on commit a57aa7e

Please sign in to comment.