How can I "intercept" Hyper Client requests to log them?

I'd like to understand how I might intercept every HTTP request a Hyper HTTP Client makes. I might want this e.g. to log each request (Uri, Method, Headers, etc) or to check a local cache before making a real request in a test scenario (like Ruby's vcr gem).

My first attempt was to build a Connector that delegates to an HttpsConnector and I got it working but that seems like the wrong level of abstraction and I can't get headers or HTTP method, only Uri.

I like the gateway example in the Hyper repo. While I understand that conceptually the client is also a Service in Hyper, I'm having trouble understanding how to provide my own Service for the Client to use.

Any guidance is appreciated. I'm about a month into learning Rust so it's highly likely that this is simple to do and I just don't know how yet.

thx!

You may want to look into the crate hyper-proxy.

1 Like

There is probably not a simple way to do it.

You may want to look into the crate hyper-proxy.

I've already done so. That crate works by creating its own ProxyConnector and hence is also not the right level of abstraction (too low) and doesn't allow for intercepting the calls to the client's API.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.