mirror of
https://github.com/httpie/cli.git
synced 2024-11-28 18:53:21 +01:00
Fail gracefully if multiple request data files are supplied (#1042)
This commit is contained in:
parent
fc45bf0fe3
commit
611bcdaab1
@ -358,13 +358,17 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
|||||||
|
|
||||||
if self.args.files and not self.args.form:
|
if self.args.files and not self.args.form:
|
||||||
# `http url @/path/to/file`
|
# `http url @/path/to/file`
|
||||||
file_fields = list(self.args.files.keys())
|
request_file = None
|
||||||
if file_fields != ['']:
|
for key, file in self.args.files.items():
|
||||||
self.error(
|
if key != '':
|
||||||
'Invalid file fields (perhaps you meant --form?): %s'
|
self.error(
|
||||||
% ','.join(file_fields))
|
'Invalid file fields (perhaps you meant --form?): %s'
|
||||||
|
% ','.join(self.args.files.keys()))
|
||||||
|
if request_file is not None:
|
||||||
|
self.error("Can't read request from multiple files")
|
||||||
|
request_file = file
|
||||||
|
|
||||||
fn, fd, ct = self.args.files['']
|
fn, fd, ct = request_file
|
||||||
self.args.files = {}
|
self.args.files = {}
|
||||||
|
|
||||||
self._body_from_file(fd)
|
self._body_from_file(fd)
|
||||||
|
@ -270,3 +270,16 @@ class TestRequestBodyFromFilePath:
|
|||||||
)
|
)
|
||||||
assert r.exit_status == ExitStatus.ERROR
|
assert r.exit_status == ExitStatus.ERROR
|
||||||
assert 'cannot be mixed' in r.stderr
|
assert 'cannot be mixed' in r.stderr
|
||||||
|
|
||||||
|
def test_multiple_request_bodies_from_file_by_path(self, httpbin):
|
||||||
|
env = MockEnvironment(stdin_isatty=True)
|
||||||
|
r = http(
|
||||||
|
'--verbose',
|
||||||
|
'POST', httpbin.url + '/post',
|
||||||
|
'@' + FILE_PATH_ARG,
|
||||||
|
'@' + FILE_PATH_ARG,
|
||||||
|
env=env,
|
||||||
|
tolerate_error_exit_status=True,
|
||||||
|
)
|
||||||
|
assert r.exit_status == ExitStatus.ERROR
|
||||||
|
assert 'from multiple files' in r.stderr
|
||||||
|
Loading…
Reference in New Issue
Block a user