net/http/httptrace: document Got1xxResponse compose behavior
Document that when Got1xxResponse hooks are composed via WithClientTrace,
both hooks are called but only the previously-registered hook's return
value is used. The new hook's return value is discarded.
This behavior comes from the generic compose function which calls both
hooks but only returns the old hook's result (trace.go lines 202-205).
Verified by testing: when two Got1xxResponse hooks are composed, both
are executed but only the old hook's error is returned.
Fixes #76669
diff --git a/src/net/http/httptrace/trace.go b/src/net/http/httptrace/trace.go
index cee13d2..65f74da 100644
--- a/src/net/http/httptrace/trace.go
+++ b/src/net/http/httptrace/trace.go
@@ -112,6 +112,10 @@
// returned before the final non-1xx response. Got1xxResponse is called
// for "100 Continue" responses, even if Got100Continue is also defined.
// If it returns an error, the client request is aborted with that error value.
+ //
+ // When Got1xxResponse hooks are composed via [WithClientTrace], both hooks
+ // are called but only the previously-registered hook's return value is used;
+ // the new hook's return value is discarded.
Got1xxResponse func(code int, header textproto.MIMEHeader) error
// DNSStart is called when a DNS lookup begins.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
// When Got1xxResponse hooks are composed via [WithClientTrace], both hooksthe policy should be documented at the struct level, we shouldn't have to repeat the same docs if we add a new hook.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
// When Got1xxResponse hooks are composed via [WithClientTrace], both hooksthe policy should be documented at the struct level, we shouldn't have to repeat the same docs if we add a new hook.
I think we can cross that bridge if and when we add any other hooks which can modify the request process. (And I don't think we should add any such hooks; Got1xxResponse sits uncomfortably here because it's about modifying the request path rather than tracing it.)
// the new hook's return value is discarded.I feel like this is documenting bad behavior, when we should fix it instead. I'd expect a request to be aborted if any Got1xxResponse hook returns an error.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |