1
0
mirror of https://github.com/httpie/cli.git synced 2025-08-10 22:42:05 +02:00

Add compressed requests (#739)

* Add optional compression of the request's content

This option allows compression of the files and/or data during uploading,

Examples:

    http --form --compress POST https://localhost/upload csv@./very-big.csv

    http -x -x POST https://localhost/upload foo=bar

    cat /var/log/system.log | http -x POST https://localhost/upload

Signed-off-by: Aleksandr Vinokurov <aleksandr.vin@gmail.com>

* Add tests for compression

Signed-off-by: Aleksandr Vinokurov <aleksandr.vin@gmail.com>

* Fix code style issues

Signed-off-by: Aleksandr Vinokurov <aleksandr.vin@gmail.com>

* Fix zlib compression api missuse in Python3

Signed-off-by: Aleksandr Vinokurov <aleksandr.vin@gmail.com>

* Remove tracing from compression logic

Signed-off-by: Aleksandr Vinokurov <aleksandr.vin@gmail.com>
This commit is contained in:
Aleksandr Vinokurov
2019-08-29 10:44:59 +02:00
committed by Jakub Roztocil
parent 2deaccf2d1
commit 5ec954c03d
4 changed files with 95 additions and 2 deletions

View File

@@ -49,12 +49,28 @@ def test_POST_JSON_data(httpbin_both):
assert r.json['json']['foo'] == 'bar'
def test_POST_JSON_data_compressed(httpbin_both):
r = http('--compress', '--compress', 'POST', httpbin_both + '/post', 'foo=bar')
assert HTTP_OK in r
assert r.json['headers']['Content-Encoding'] == 'deflate'
assert r.json['data'].startswith('data:application/octet-stream;')
assert r.json['json'] is None
def test_POST_form(httpbin_both):
r = http('--form', 'POST', httpbin_both + '/post', 'foo=bar')
assert HTTP_OK in r
assert '"foo": "bar"' in r
def test_POST_form_compressed(httpbin_both):
r = http('--form', '--compress', '--compress', 'POST', httpbin_both + '/post', 'foo=bar')
assert HTTP_OK in r
assert r.json['headers']['Content-Encoding'] == 'deflate'
assert r.json['data'] == ""
assert '"foo": "bar"' not in r
def test_POST_form_multiple_values(httpbin_both):
r = http('--form', 'POST', httpbin_both + '/post', 'foo=bar', 'foo=baz')
assert HTTP_OK in r
@@ -69,6 +85,31 @@ def test_POST_stdin(httpbin_both):
assert FILE_CONTENT in r
def test_POST_stdin_compressed(httpbin_both):
with open(FILE_PATH) as f:
env = MockEnvironment(stdin=f, stdin_isatty=False)
r = http('--form', '--compress', '--compress', 'POST', httpbin_both + '/post', env=env)
assert HTTP_OK in r
assert r.json['headers']['Content-Encoding'] == 'deflate'
assert r.json['data'] == ""
assert FILE_CONTENT not in r
def test_POST_file(httpbin_both):
r = http('--form', 'POST', httpbin_both + '/post', 'file@' + FILE_PATH)
assert HTTP_OK in r
assert FILE_CONTENT in r
def test_POST_file_compressed(httpbin_both):
r = http('--form', '--compress', '--compress', 'POST', httpbin_both + '/post', 'file@' + FILE_PATH)
assert HTTP_OK in r
assert r.json['headers']['Content-Encoding'] == 'deflate'
assert r.json['headers']['Content-Type'].startswith('multipart/form-data; boundary=')
assert r.json['files'] == {}
assert FILE_CONTENT not in r
def test_headers(httpbin_both):
r = http('GET', httpbin_both + '/headers', 'Foo:bar')
assert HTTP_OK in r