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

Add --raw to allow specifying the raw request body as an alternative to stdin (#1062)

* Add --raw to allow specifying the raw request body without extra processing

As an alternative to `stdin`.

Co-authored-by: Elena Lape <elapinskaite@gmail.com>
Co-authored-by: Jakub Roztocil <jakub@roztocil.co>

* Update README.rst

Co-authored-by: Jakub Roztocil <jakub@roztocil.co>

* Update README.rst

Co-authored-by: Jakub Roztocil <jakub@roztocil.co>

* Fix default HTTP method on empty data

Co-authored-by: Elena Lape <elapinskaite@gmail.com>
Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
This commit is contained in:
Mickaël Schoentgen
2021-05-24 14:29:54 +02:00
committed by GitHub
parent e2d43c14ce
commit 0001297f41
12 changed files with 173 additions and 12 deletions

View File

@@ -92,6 +92,19 @@ def test_compress_form(httpbin_both):
assert '"foo": "bar"' not in r
def test_compress_raw(httpbin_both):
r = http(
'--raw',
FILE_CONTENT,
'--compress',
'--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())
def test_compress_stdin(httpbin_both):
env = MockEnvironment(
stdin=StdinBytesIO(FILE_PATH.read_bytes()),

View File

@@ -45,6 +45,11 @@ class TestImplicitHTTPMethod:
assert HTTP_OK in r
assert r.json['form'] == {'foo': 'bar'}
def test_implicit_POST_raw(self, httpbin):
r = http('--raw', 'foo bar', httpbin.url + '/post')
assert HTTP_OK in r
assert r.json['data'] == 'foo bar'
def test_implicit_POST_stdin(self, httpbin):
env = MockEnvironment(
stdin_isatty=False,

View File

@@ -103,6 +103,12 @@ def test_POST_form_multiple_values(httpbin_both):
}
def test_POST_raw(httpbin_both):
r = http('--raw', 'foo bar', 'POST', httpbin_both + '/post')
assert HTTP_OK in r
assert '"foo bar"' in r
def test_POST_stdin(httpbin_both):
env = MockEnvironment(
stdin=StdinBytesIO(FILE_PATH.read_bytes()),
@@ -140,6 +146,35 @@ def test_form_POST_file_redirected_stdin(httpbin):
assert 'cannot be mixed' in r.stderr
def test_raw_POST_key_values_supplied(httpbin):
r = http(
'--raw',
'foo bar',
'POST',
httpbin + '/post',
'foo=bar',
tolerate_error_exit_status=True,
)
assert r.exit_status == ExitStatus.ERROR
assert 'cannot be mixed' in r.stderr
def test_raw_POST_redirected_stdin(httpbin):
r = http(
'--raw',
'foo bar',
'POST',
httpbin + '/post',
tolerate_error_exit_status=True,
env=MockEnvironment(
stdin='some=value',
stdin_isatty=False,
),
)
assert r.exit_status == ExitStatus.ERROR
assert 'cannot be mixed' in r.stderr
def test_headers(httpbin_both):
r = http('GET', httpbin_both + '/headers', 'Foo:bar')
assert HTTP_OK in r

View File

@@ -10,6 +10,27 @@ def test_offline():
assert 'GET /foo' in r
def test_offline_raw():
r = http(
'--offline',
'--raw',
'foo bar',
'https://this-should.never-resolve/foo',
)
assert 'POST /foo' in r
assert 'foo bar' in r
def test_offline_raw_empty_should_use_POST():
r = http(
'--offline',
'--raw',
'',
'https://this-should.never-resolve/foo',
)
assert 'POST /foo' in r
def test_offline_form():
r = http(
'--offline',

View File

@@ -141,6 +141,12 @@ class TestVerboseFlag:
assert HTTP_OK in r
assert r.count('__test__') == 2
def test_verbose_raw(self, httpbin):
r = http('--verbose', '--raw', 'foo bar',
'POST', httpbin.url + '/post',)
assert HTTP_OK in r
assert 'foo bar' in r
def test_verbose_form(self, httpbin):
# https://github.com/httpie/httpie/issues/53
r = http('--verbose', '--form', 'POST', httpbin.url + '/post',

View File

@@ -20,6 +20,19 @@ def test_unicode_headers_verbose(httpbin):
assert UNICODE in r
def test_unicode_raw(httpbin):
r = http('--raw', u'test %s' % UNICODE, 'POST', httpbin.url + '/post')
assert HTTP_OK in r
assert r.json['data'] == u'test %s' % UNICODE
def test_unicode_raw_verbose(httpbin):
r = http('--verbose', '--raw', u'test %s' % UNICODE,
'POST', httpbin.url + '/post')
assert HTTP_OK in r
assert UNICODE in r
def test_unicode_form_item(httpbin):
r = http('--form', 'POST', httpbin.url + '/post', u'test=%s' % UNICODE)
assert HTTP_OK in r