snoyberg / http-client

An HTTP client engine, intended as a base layer for more user-friendly packages.
280 stars 194 forks source link

Keeping up with the Joneses: http-tracing a la Golang #233

Open bitemyapp opened 8 years ago

bitemyapp commented 8 years ago

https://blog.golang.org/http-tracing

Quoting:

The tracing mechanism is designed to trace the events in the lifecycle of a single http.Transport.RoundTrip. However, a client may make multiple round trips to complete an HTTP request. For example, in the case of a URL redirection, the registered hooks will be called as many times as the client follows HTTP redirects, making multiple requests. Users are responsible for recognizing such events at the http.Client level. The program below identifies the current request by using an http.RoundTripper wrapper.

The program will follow the redirect of google.com to www.google.com and will output:

Connection reused for https://google.com? false
Connection reused for https://www.google.com/? false

The Transport in the net/http package supports tracing of both HTTP/1 and HTTP/2 requests.

@mwotton's request for tracking redirects is a start on this.

I have no illusions about this being a substantial amount of work and possibly being appropriate for a separate library built on top, but it may require adding hooks or exposing implementation.

snoyberg commented 8 years ago

Does this address things at all?

https://www.stackage.org/haddock/lts-7.2/http-client-0.4.31.1/Network-HTTP-Client.html#g:2

It doesn't have information about connection reuse AFAIK, but that could be added to Response itself I believe.

bitemyapp commented 8 years ago

If it was extended, possibly. I'd need to plumb Go's thing to see what else is missing.