Skip to content

Commit

Permalink
add gzip support (for testing, does not work with server yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Oct 23, 2023
1 parent ad169f2 commit 7701ad3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions aggrec/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import gzip
import hashlib
import logging
from urllib.parse import urljoin
Expand Down Expand Up @@ -72,8 +73,9 @@ def main() -> None:
default="histogram",
)
parser.add_argument(
"--debug", dest="debug", action="store_true", help="Enable debugging"
"--gzip", action="store_true", help="Compress payload using GZIP"
)
parser.add_argument("--debug", action="store_true", help="Enable debugging")

args = parser.parse_args()

Expand All @@ -98,8 +100,10 @@ def main() -> None:
req = requests.Request(
"POST",
urljoin(args.server, f"/api/v1/aggregate/{args.type}"),
data=fp.read(),
data=gzip.compress(fp.read()) if args.gzip else fp.read(),
)
if args.gzip:
req.headers["Content-Encoding"] = "gzip"

req = req.prepare()
req.headers["Content-Type"] = DEFAULT_CONTENT_TYPE
Expand All @@ -120,7 +124,9 @@ def main() -> None:

resp = session.send(req)
resp.raise_for_status()

print(resp)
print(resp.headers)
print(resp.text)


Expand Down

0 comments on commit 7701ad3

Please sign in to comment.