Skip to content
Discussion options

You must be logged in to vote

Hi!
I believe you can simply replace event hooks with custom transports as follows:

importhttpxasyncdefrequest_hook(self, request):
ifself.tokenisNoneorself.token_has_expired():
self.token=awaitself.client.get("/token_endpoint")
classCustomTransport(httpx.AsyncHTTPTransport):
asyncdefhandle_async_request(self, request: httpx.Request) ->httpx.Response:
ifnotrequest.extensions.get("disable_hooks", False):
awaitrequest_hook(request)
returnawaitsuper().handle_async_request(request)
client=httpx.AsyncClient(transport=CustomTransport())
awaitclient.get("/token_endpoint") # hook_worksawaitclient.get("/token_endpoint", e…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mijolabs
Comment options

Answer selected bymijolabs
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Category
General
Labels
None yet
2 participants
@mijolabs@karpetrosyan