Replies: 1 comment
|
yes—use a request event hook to inspect the headers after HTTPX prepares the request and applies authentication, just before passing it to the transport: import httpx
def dump_headers(request: httpx.Request) -> None:
hidden = {"authorization", "proxy-authorization", "cookie"}
for name, value in request.headers.multi_items():
print(name, "<redacted>" if name.lower() in hidden else value)
with httpx.Client(event_hooks={"request": [dump_headers]}) as client:
response = client.post(
"https://your-api.example/items", # replace with your endpoint
json={"name": "example"},
)The hook sees generated headers such as For inspection after the call, use
Client certificates are part of TLS, not HTTP headers. Also, this exposes HTTPX's request headers, not a byte-for-byte capture of the transport's HTTP/2 encoding or proxy exchanges. Verified with HTTPX 0.28.1 against a local HTTP server: JSON plus Basic auth, a followed redirect, multipart content headers, and an async hook. Testing and drafting were AI-assisted. |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
is it possible to gather request headers somehow?
There are
headersas an option, but the library itself also modifies the headers by other configuration options for eg authorization, maybe certificates, content type, content length etc.Thanks
All reactions