From ad8fc57df3dfd4f7cbaa2ee7a20bb54c765150b0 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 11 Jan 2022 16:41:25 +0000 Subject: [PATCH] scripts/test-sender: Support --gzip=bad --- scripts/testing/gateway-responses/test-sender.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/testing/gateway-responses/test-sender.py b/scripts/testing/gateway-responses/test-sender.py index 52e7aca..93f2fa0 100644 --- a/scripts/testing/gateway-responses/test-sender.py +++ b/scripts/testing/gateway-responses/test-sender.py @@ -27,9 +27,14 @@ send_message: s = requests.Session() if args.gzip: - if args.gzip == 'good': - msg = zlib.compress(msg.encode('utf-8')) - s.headers['Content-Encoding'] = 'gzip' + # We assume that the argparse setup is enforcing the value being + # valid, i.e. `'good'` if it's not `'bad'`. + msg = zlib.compress(msg.encode('utf-8')) + s.headers['Content-Encoding'] = 'gzip' + + if args.gzip == 'bad': + # Prepend a character so it's not a valid gzip header + msg = b'w' + msg r = s.post(upload_url, data=msg) @@ -55,7 +60,7 @@ if __name__ == "__main__": __parser.add_argument( '--gzip', - choices=('good'), + choices=('good', 'bad'), help='Specify to gzip-compress the request body', )