Skip to content

Auto headers inserted into headers._list while not into headers._dict #1203

Closed

Description

@j178

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

Request.prepare() insert auto headers into headers.raw (ie headers._list), but not into the headers._dict.

httpx/httpx/_models.py

Lines 650 to 651 in 924fa8c

for item in reversed(auto_headers):
self.headers.raw.insert(0, item)

To reproduce

>>> import httpx
>>> client = httpx.Client()
>>> request = client.build_request("GET", "https://google.com")
>>> requests.headers
Headers({'host': 'google.com', 'user-agent': 'python-httpx/0.14.1', 'accept': '*/*', 'accept-encoding': 'gzip, deflate, br', 'connection': 'keep-alive'})
>>> "host" in request.headers
False
>>> request.headers.pop("host")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\programs\anaconda3\lib\_collections_abc.py", line 801, in pop
    del self[key]
  File "E:\projects\pycharm\httpx\httpx\_models.py", line 536, in __delitem__
    del self._dict[del_key]
KeyError: b'host'

Environment

  • OS: Windows/macOS
  • Python version: 3.7.6
  • HTTPX version: 0.14.1

Activity

  1. lovelydinosaur commented on Aug 20, 2020

    @lovelydinosaur
    Member

    Introduced by #1089.
    Resolved and test case'd in #1205.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions