Skip to content

Improving documentation/behavior for event hooks #1637

Answered by tomchristie
K900 asked this question in Ideas
Discussion options

You must be logged in to vote

Good question.

The request hooks:

https://github.com/encode/httpx/blob/master/httpx/_client.py#L902-L903

And response hooks:

https://github.com/encode/httpx/blob/master/httpx/_client.py#L882-L883

Both simply pass the request or response instance to the function.

To the extent that request/response instances have some mutable aspects, you could alter some bits of them in the function as a side-effect. For instance:

def hook(request):
    request.headers['X-Custom'] = '...'

That's not particularly an intentional design feature, and I have considered if we'd do better with headers being an immutable data structure or not. (Although even if they were, it'd still be fiddly to make the entire r…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@K900
Comment options

@tomchristie
Comment options

@K900
Comment options

@tomchristie
Comment options

@K900
Comment options

Answer selected by tomchristie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants