Allow passing custom arguments to http client + Add better documentation on the subject
Hello,
I'm aware of the ability to set a custom http_client parameter but that is now requiring a bit more.
Looking at the code now:
self._http_client = http_client or httpx.AsyncClient(
transport=httpx.ASGITransport(app=self.fastapi, raise_app_exceptions=False),
base_url=self._base_url,
timeout=10.0,
)
The latest version requires copying the base url and ASGITransport call. In my use case, I'd like to just override the timeout.
Could we add a new parameter such as client_args with a dictionary of options to overlay when creating the client. For example:
self._http_client = http_client or httpx.AsyncClient(
**{{
transport=httpx.ASGITransport(app=self.fastapi, raise_app_exceptions=False),
base_url=self._base_url,
timeout=10.0,
}, **client_args}
)
This would have the benefit of allowing a user to override a single http client parameter without having to know what else to pass.
Sure. That's a good idea :) Just need to make sure that client_args has a strict type definition that matches what httpx.AsyncClient expects. And also maybe call it http_client_args to be more specific
Sounds great! That all makes sense.
added a pull request #98