You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classLoggingHTTPAdapter(requests.adapters.HTTPAdapter):
"""Adapter to log request and response."""defsend(self, request, *args, **kwargs):
sensitive_params=conf.SENSITIVE_PARAMS# transaction ID to identify the logs.trans_id=util.generate_uuid()
headers=util.filter_sensitive_information(
request.headers, sensitive_params
)
log.info(f"<{trans_id}> Request: {request.method}{request.url}")
log.info(f"<{trans_id}> Request headers: {headers}")
log.info(f"<{trans_id}> Request body: {request.body}")
resp=super().send(request, *args, **kwargs)
headers=util.filter_sensitive_information(
resp.headers, sensitive_params
)
log.info(f"<{trans_id}> Response: {resp.status_code}{resp.reason}")
log.info(f"<{trans_id}> Response headers: {headers}")
log.info(f"<{trans_id}> Response body: {resp.content}")
# Store the transaction ID in the response object, so that it can be# added to the logs from test cases.resp.__dict__["transaction_id"] =trans_idreturnrespdefmount_adapter(session):
# currently we only have TimeoutHTTPAdapter and LoggingHTTPAdapter,# when we add more in the future, we can use this function to mount# our adapters.adapters= [LoggingHTTPAdapter()]
foradapterinadapters:
session.mount("http://", adapter)
session.mount("https://", adapter)
With httpx, would I need to wrap/subclass a Dispatcher or Client class instead?
The Dispatcher interface is a very close equivalent to the Adapter interface.
You could achieve the same usage you’ve given an example of by subclassing the default Dispatch implementation (ConnectionPool), and passing it to the client with dispatch=.
That’d be equivalent to how this example subclasses HTTPAdapter, and uses mount to add it to the client.
Activity
lovelydinosaur commentedon Jul 24, 2019
The Dispatcher interface is a very close equivalent to the Adapter interface.
You could achieve the same usage you’ve given an example of by subclassing the default Dispatch implementation (ConnectionPool), and passing it to the client with dispatch=.
That’d be equivalent to how this example subclasses HTTPAdapter, and uses mount to add it to the client.
StephenBrown2 commentedon Jul 24, 2019
Excellent. I'll give that a shot tomorrow. Thanks!
sethmlarson commentedon Jul 28, 2019
This issue is no longer needed it seems? Reopen if I'm wrong here :)
StephenBrown2 commentedon Jul 28, 2019
Yup, the custom Dispatcher worked for me, was going to update on Monday once I had a bit more testing done. Good to close 👍