diff --git a/transcoder.go b/transcoder.go index 2fea634..ec99e1a 100644 --- a/transcoder.go +++ b/transcoder.go @@ -471,18 +471,6 @@ func (o *operation) queryValues() url.Values { } func (o *operation) handle() { - // Deferred function to capture http.ErrAbortHandler panics. - defer func() { - if recovered := recover(); recovered != nil { - if err, ok := recovered.(error); ok { - if errors.Is(err, http.ErrAbortHandler) { - return - } - } - panic(recovered) //nolint:forbidigo // re-throw the panic if unknown - } - }() - o.clientEnveloper, _ = o.client.protocol.(envelopedProtocolHandler) o.clientPreparer, _ = o.client.protocol.(clientBodyPreparer) if o.clientPreparer != nil { diff --git a/vanguard_restxrpc_test.go b/vanguard_restxrpc_test.go index a0fe38e..4556e83 100644 --- a/vanguard_restxrpc_test.go +++ b/vanguard_restxrpc_test.go @@ -18,6 +18,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -168,9 +169,6 @@ func TestMux_RESTxRPC(t *testing.T) { query[key] = values } req.URL.RawQuery = query.Encode() - // Inject http.Server into the request context for httputil.ReverseProxy. - svr := &http.Server{} //nolint:gosec // dummy server for testing - req = req.WithContext(context.WithValue(req.Context(), http.ServerContextKey, svr)) return req } type output struct { @@ -552,7 +550,25 @@ func TestMux_RESTxRPC(t *testing.T) { t.Log("req:", string(debug)) rsp := httptest.NewRecorder() - opts.mux.handler.ServeHTTP(rsp, req) + + func() { + // Capture http.ErrAbortHanlder panics. + defer func() { + if recovered := recover(); recovered != nil { + if err, ok := recovered.(error); ok { + if errors.Is(err, http.ErrAbortHandler) { + return + } + } + t.Error("unexpected panic:", recovered) + } + }() + // Inject http.Server into the request context to convince + // httputil.ReverseProxy we are in a server context. + svr := &http.Server{} //nolint:gosec // dummy server for testing + req = req.WithContext(context.WithValue(req.Context(), http.ServerContextKey, svr)) + opts.mux.handler.ServeHTTP(rsp, req) + }() result := rsp.Result() defer result.Body.Close()