From 3654794014959a26c201b365e9e8864435413a37 Mon Sep 17 00:00:00 2001 From: Vinay Kumar Date: Wed, 28 Oct 2026 12:07:07 +0530 Subject: [PATCH] Fixes #1972: Add tests for automatic request compression with single --compress flag This adds end-to-end JSON and raw-body cases with a single --compress flag, which tests the normal case where compression occurs because the result is smaller. --- tests/test_compress.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_compress.py b/tests/test_compress.py index de5d8a7c48..2e1a9d0228 100644 --- a/tests/test_compress.py +++ b/tests/test_compress.py @@ -138,3 +138,31 @@ def test_compress_file(httpbin_both): 'multipart/form-data; boundary=') assert r.json['files'] == {} assert FILE_CONTENT not in r + + +def test_compress_json_normal(httpbin_both): + # Test normal compression with one --compress flag where compression + # reduces size (should compress) + r = http( + '--compress', + httpbin_both + '/post', + 'foo=bar', + ) + assert HTTP_OK in r + assert r.json['headers']['Content-Encoding'] == 'deflate' + assert_decompressed_equal(r.json['data'], '{"foo": "bar"}') + assert r.json['json'] is None + + +def test_compress_raw_normal(httpbin_both): + # Test normal compression with one --compress flag where compression + # reduces size (should compress) + r = http( + '--raw', + FILE_CONTENT, + '--compress', + httpbin_both + '/post', + ) + assert HTTP_OK in r + assert r.json['headers']['Content-Encoding'] == 'deflate' + assert_decompressed_equal(r.json['data'], FILE_CONTENT.strip()) \ No newline at end of file