-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingnewNeeds triage. Comments are welcome!Needs triage. Comments are welcome!
Description
I'm getting weird behavior when specifying headers on the command line.
Checklist
-
I've searched for similar issues.
-
I'm using the latest version of HTTPie.
- httpie v3.2.4
- Win11 Pro x64 24H2
- Python 3.10.0
Note that I'm new to httpie.
Minimal reproduction code and steps
Running the the example from https://httpie.io/docs/cli/http-headers (adding --offline so it outputs the request headers), the only header that shows up from those given on the command line is the Referer header. (I assume the rest are expected default headers):
C:\httpie>http --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar Referer:https://httpie.org/
GET /headers HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: pie.dev
Referer: https://httpie.org/ # only header from the command line
If I remove a header from the command line all the other headers show up:
C:\httpie>http --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar
GET /headers HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: valued-visitor=yes;foo=bar # printed now
Host: pie.dev
User-Agent: Bacon/1.0 # printed now
X-Foo: Bar # printed now
If instead of removing a header I add another ( X-Bar:Foo in this example), the problem changes to an error:
C:\httpie>http --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Bar:Foo X-Foo:Bar Referer:https://httpie.org/
http: error: KeyError: 'Referer'
Expected result
The headers on the command line get printed, no bogus errors
Debug output
C:\httpie>http --debug --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar Referer:https://httpie.org/
HTTPie 3.2.4
Requests 2.32.4
Pygments 2.19.2
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
C:\Python310\python.exe
Windows 10
<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x000001DDD0644A60>,
'args': Namespace(),
'as_silent': <function Environment.as_silent at 0x000001DDD0644940>,
'colors': 256,
'config': {'default_options': []},
'config_dir': WindowsPath('C:/Users/mburr/AppData/Roaming/httpie'),
'devnull': <property object at 0x000001DDD05E47C0>,
'is_windows': True,
'log_error': <function Environment.log_error at 0x000001DDD06449D0>,
'program_name': 'http',
'quiet': 0,
'rich_console': <functools.cached_property object at 0x000001DDD05CE440>,
'rich_error_console': <functools.cached_property object at 0x000001DDD05CF0D0>,
'show_displays': True,
'stderr': <colorama.ansitowin32.StreamWrapper object at 0x000001DDD05CDFC0>,
'stderr_isatty': True,
'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
'stdin_encoding': 'utf-8',
'stdin_isatty': True,
'stdout': <colorama.ansitowin32.StreamWrapper object at 0x000001DDD05CC2B0>,
'stdout_encoding': 'utf-8',
'stdout_isatty': True}>
<PluginManager {'adapters': [],
'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
<class 'httpie.plugins.builtin.DigestAuthPlugin'>,
<class 'httpie.plugins.builtin.BearerAuthPlugin'>],
'converters': [],
'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
<class 'httpie.output.formatters.json.JSONFormatter'>,
<class 'httpie.output.formatters.xml.XMLFormatter'>,
<class 'httpie.output.formatters.colors.ColorFormatter'>]}>
>>> requests.request(**{'auth': None,
'data': RequestJSONDataDict(),
'headers': <HTTPHeadersDict('User-Agent': b'Bacon/1.0', 'Cookie': b'valued-visitor=yes;foo=bar', 'X-Foo': b'Bar', 'Referer': b'https://httpie.org/')>,
'method': 'get',
'params': <generator object MultiValueOrderedDict.items at 0x000001DDD1432B90>,
'url': 'http://pie.dev/headers'})
GET /headers HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: pie.dev
Referer: https://httpie.org/
C:\httpie>http --debug --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Bar:Foo X-Foo:Bar Referer:https://httpie.org/
HTTPie 3.2.4
Requests 2.32.4
Pygments 2.19.2
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
C:\Python310\python.exe
Windows 10
<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x000001F7282D4A60>,
'args': Namespace(),
'as_silent': <function Environment.as_silent at 0x000001F7282D4940>,
'colors': 256,
'config': {'default_options': []},
'config_dir': WindowsPath('C:/Users/mburr/AppData/Roaming/httpie'),
'devnull': <property object at 0x000001F728274720>,
'is_windows': True,
'log_error': <function Environment.log_error at 0x000001F7282D49D0>,
'program_name': 'http',
'quiet': 0,
'rich_console': <functools.cached_property object at 0x000001F72825E440>,
'rich_error_console': <functools.cached_property object at 0x000001F72825F0D0>,
'show_displays': True,
'stderr': <colorama.ansitowin32.StreamWrapper object at 0x000001F72825DFC0>,
'stderr_isatty': True,
'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
'stdin_encoding': 'utf-8',
'stdin_isatty': True,
'stdout': <colorama.ansitowin32.StreamWrapper object at 0x000001F72825C2B0>,
'stdout_encoding': 'utf-8',
'stdout_isatty': True}>
<PluginManager {'adapters': [],
'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
<class 'httpie.plugins.builtin.DigestAuthPlugin'>,
<class 'httpie.plugins.builtin.BearerAuthPlugin'>],
'converters': [],
'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
<class 'httpie.output.formatters.json.JSONFormatter'>,
<class 'httpie.output.formatters.xml.XMLFormatter'>,
<class 'httpie.output.formatters.colors.ColorFormatter'>]}>
>>> requests.request(**{'auth': None,
'data': RequestJSONDataDict(),
'headers': <HTTPHeadersDict('User-Agent': b'Bacon/1.0', 'Cookie': b'valued-visitor=yes;foo=bar', 'X-Bar': b'Foo', 'X-Foo': b'Bar', 'Referer': b'https://httpie.org/')>,
'method': 'get',
'params': <generator object MultiValueOrderedDict.items at 0x000001F7290B2B90>,
'url': 'http://pie.dev/headers'})
http: error: KeyError: 'Referer'
Traceback (most recent call last):
File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python310\Scripts\http.exe\__main__.py", line 7, in <module>
File "C:\Python310\lib\site-packages\httpie\__main__.py", line 9, in main
exit_status = main()
File "C:\Python310\lib\site-packages\httpie\core.py", line 162, in main
return raw_main(
File "C:\Python310\lib\site-packages\httpie\core.py", line 140, in raw_main
handle_generic_error(e)
File "C:\Python310\lib\site-packages\httpie\core.py", line 100, in raw_main
exit_status = main_program(
File "C:\Python310\lib\site-packages\httpie\core.py", line 213, in program
for message in messages:
File "C:\Python310\lib\site-packages\httpie\client.py", line 93, in collect_messages
transform_headers(request, prepared_request)
File "C:\Python310\lib\site-packages\httpie\client.py", line 227, in transform_headers
apply_missing_repeated_headers(
File "C:\Python310\lib\site-packages\httpie\client.py", line 257, in apply_missing_repeated_headers
new_headers.popone(prepared_name)
KeyError: 'Referer'
Any help is appreciated.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingnewNeeds triage. Comments are welcome!Needs triage. Comments are welcome!