Files
moby/client/client_responsehook.go
Sebastiaan van Stijn c7657f8d73 client: ResponseHook: remove error return
ResponseHooks are executed as part of the http.RoundTripper, which is
documented as;

    // RoundTrip should not attempt to interpret the response. In
    // particular, RoundTrip must return err == nil if it obtained
    // a response, regardless of the response's HTTP status code.
    // A non-nil err should be reserved for failure to obtain a
    // response. Similarly, RoundTrip should not attempt to
    // handle higher-level protocol details such as redirects,
    // authentication, or cookies.

So errors should be reserved for failing to make a request; if a
webhook would return an error for other reasons, that would break
this contract (and prevent running other response-hooks), so we should
consider response-hooks to never return an error, and users of this
functionality to handle errors in other ways.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-01-23 18:21:13 +01:00

24 lines
352 B
Go

package client
import (
"net/http"
)
type responseHookTransport struct {
base http.RoundTripper
hooks []ResponseHook
}
func (t *responseHookTransport) RoundTrip(req *http.Request) (*http.Response, error) {
resp, err := t.base.RoundTrip(req)
if err != nil {
return resp, err
}
for _, h := range t.hooks {
h(resp)
}
return resp, nil
}