-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging outbound request from client #1418
Comments
You can sort of do what you want, but not all of it is especially easy. For logging request and response, that you can do by logging whatever you want just before calling debug!("req = {:?}", req);
client.request(req)
.map(|res| {
debug!("res = {:?}", res);
res
}) In order to get a reference to the transport being used, you'd probably need to write a custom Probably this is also related to #1402. (As this seems more like a question around how to do something in hyper, and not a bug that something doesn't work, I'm going to close for now.) |
Hi Sean. Thanks for the quick reply, and sorry: I should have been more specific. I've already attempted something like what you describe above, however: hyper tacks on a few headers (transfer encoding, Date header, etc) before sending, and I'd like to log the request as it actually goes out over the wire, including those headers. I currently have a tracer that works by implementing a custom connect and wrapping the TcpStream, but to sensibly log the request I then find I have to re-parse it to get the method, headers, body, etc. It would be nice to have a logging callback, maybe somewhere around https://docs.rs/hyper/0.11.12/src/hyper/client/mod.rs.html#193, that could pass a reference to the transport and the request after the extra headers have been added. Is that sensible? Otherwise, is there a way of doing this already? Thanks. |
Do you know what these kinds of APIs look like in other HTTP client libraries? |
@sfackler sorry for taking a while to respond. I don't really have any examples of this in other client libraries, but I don't think there are many other libraries that would have a need for it. Put differently, I think hyper is a bit more opaque than other HTTP client libraries I've worked with. In particular
Don't get me wrong, I think it's great that it works like this, I would just really like some way to special-case for TCP connections when I have a need to access the transport layer. |
Hi. I'm trying to write a tracer which logs exactly what requests get sent over the wire, and preferably including local and remote ip/port. I realize hyper is agnostic to transport, but is there some way of logging the request and response struct, and getting passed a reference to the transport for diagnostics purposes?
Has anyone done anything like that before?
The text was updated successfully, but these errors were encountered: