From 08885194c8c7110a51e47091fe8070de37110e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arif=20U=C4=9Fur=20=C3=87elik?= <217665348+augrclk@users.noreply.github.com> Date: Mon, 12 Oct 2026 10:17:29 +0300 Subject: [PATCH] Test automatic request compression for JSON and raw bodies --- AUTHORS.md | 1 + tests/test_compress.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 5351307d84..ddd34e5c3b 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -39,3 +39,4 @@ - [Elena Lape](https://github.com/elenalape) - [Rohit Sehgal](https://github.com/r0hi7) - [Bartłomiej Jacak](https://github.com/bartekjacak) +- [Arif Uğur Çelik](https://github.com/augrclk) diff --git a/tests/test_compress.py b/tests/test_compress.py index de5d8a7c48..a6db0267bf 100644 --- a/tests/test_compress.py +++ b/tests/test_compress.py @@ -11,6 +11,8 @@ import base64 import zlib +import pytest + from .fixtures import FILE_PATH, FILE_CONTENT from httpie.status import ExitStatus from .utils import StdinBytesIO, http, HTTP_OK, MockEnvironment @@ -53,6 +55,22 @@ def test_compress_skip_negative_ratio(httpbin_both): assert r.json['json'] == {'foo': 'bar'} +@pytest.mark.parametrize('options, items, expected_body', [ + ([], ['foo=' + 'bar' * 1024], '{"foo": "' + 'bar' * 1024 + '"}'), + (['--raw', 'bar' * 1024], [], 'bar' * 1024), +], ids=['json', 'raw']) +def test_compress_positive_ratio(httpbin_both, options, items, expected_body): + r = http('--compress', *options, 'POST', httpbin_both + '/post', *items) + + assert HTTP_OK in r + assert r.json['headers']['Content-Encoding'] == 'deflate' + assert_decompressed_equal(r.json['data'], expected_body) + + compressed_body = base64.b64decode(r.json['data'].split(',', 1)[1]) + assert len(compressed_body) < len(expected_body.encode()) + assert int(r.json['headers']['Content-Length']) == len(compressed_body) + + def test_compress_force_with_negative_ratio(httpbin_both): r = http( '--compress',