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
net/http/httptrace: expose transport-added request headers #19761
Comments
Have you tried https://golang.org/pkg/net/http/httptrace/#ClientTrace? See https://blog.golang.org/http-tracing Do you have a concrete suggestion for what's missing in the httptrace package? |
/cc @rakyll @tombergan |
We could use httptrace if the transport request was sent into WroteRequest similar to how conn is passed into GotConn. However I don't think we should have to look into the trace to find the complete set of request headers. I'd love it if Response.Request.Header included the extra headers set in transport. I can create a code snippet if I'm not explaining this well, however my code will likely confuse you more! |
That's not an option. We can't mutate that. It would break existing code, and possibly introduce data races. It's a backwards incompatible change. First, let's make a list of the complete set of headers which can be added implicitly. Only "Accept-Encoding" and "Connection", or more? And what do you need them for? |
We have an internal application that polls a great many services over http for service health. When we detect a failure we capture as much information as possible to help diagnose the failure. Since we give users the option to set custom headers in their tests we provide them what we thought was a complete list of headers as part of the failure attributes. Recently we had an issue using httptracer on an http/2 connection (where we did not realise we were falling through to http/2) and went down the path of diagnosing why we were re-using connections when we had explicitly disabled keepalives. The service receiving these polls dumped out the request including headers which included Accept-Encoding and Connection. If these were exposed as part of our failure we'd have had more insight. I understand we can't mutate Request, however transport is not sending the same request as the user sets by adding these headers in flight. I'd be OK with using httptracer to expose this if possible though the purist in me thinks the response should include the complete request sent. |
This is a reasonable feature request.
I think httptrace is the best place for this, actually. It's not possible to mutate Request for the reasons that Brad mentioned. It's unfortunate that WroteHeaders() doesn't take an Info argument, and it's too late to change the signature. The possible solutions include:
|
Change https://golang.org/cl/67430 mentions this issue: |
Gently pinging the issue here: @tombergan any ideas for this issue? -- as I can see that the CL has an unresolved -2 by the original author. |
Some headers, which are set or modified by the http library, are not written to the standard http.Request.Header and are not included as part of http.Response.Request.Header. Exposing all headers alleviates this problem. This is not a complete solution to 19761 since it does not have http/2 support. Updates #19761 Change-Id: Ie8d4f702f4f671666b120b332378644f094e288b Reviewed-on: https://go-review.googlesource.com/67430 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Change https://golang.org/cl/121236 mentions this issue: |
Updates #19761 Change-Id: Iac3bd4c40002f8e348452b50bff54dee3210d447 Reviewed-on: https://go-review.googlesource.com/121236 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Change https://golang.org/cl/122816 mentions this issue: |
ClientTrace.WroteHeaderField was added in Go 1.11. Updates golang/go#19761 (fixes after vendor into std) Change-Id: I9a7af31b8601b9cd6efdee63d31a6c05102473d2 Reviewed-on: https://go-review.googlesource.com/122816 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org>
Change https://golang.org/cl/122591 mentions this issue: |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.8
I'd like to record request headers to visualise in an http polling application. There are headers set on the underlying transport request such as compression or keepalives that I am not able to view via the Response.Request.Headers or in any other way I can see.
The text was updated successfully, but these errors were encountered: