Keep Headers._encoding when constructing from another Headers instance #3763
Replies: 1 comment
|
You have identified a subtle behavior in Here is a breakdown of why this happens, how to ensure UTF-8 header encoding today, and how it relates to client design: 1. Why
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I’m trying to build a custom client that defaults header encoding to UTF-8 (related: https://github.com/encode/httpx/issues/3238).
While looking at
httpx.Headers.__init__, it seems that when you pass an existing Headers instance, it copies ._list but ignores ._encoding.httpx/httpx/_models.py
Lines 151 to 164 in ae1b9f6
If I do Headers(existing_headers) (what BaseClient._merge_headers does), I expected it to behave like a copy, including keeping the same encoding; unless I explicitly pass encoding=.
I believe it should carry over its encoding (unless encoding is provided):
If this is intentional, what’s the recommended way to make a client default to UTF-8 header encoding without losing it when headers get copied around?
All reactions