mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:58:45 +02:00
fix(reverseproxy): properly suppress http2.errStreamClosed
This commit is contained in:
@@ -33,6 +33,8 @@ import (
|
|||||||
U "github.com/yusing/go-proxy/internal/utils"
|
U "github.com/yusing/go-proxy/internal/utils"
|
||||||
"golang.org/x/net/http/httpguts"
|
"golang.org/x/net/http/httpguts"
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
|
|
||||||
|
_ "unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A ProxyRequest contains a request to be rewritten by a [ReverseProxy].
|
// A ProxyRequest contains a request to be rewritten by a [ReverseProxy].
|
||||||
@@ -169,6 +171,9 @@ func copyHeader(dst, src http.Header) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:linkname errStreamClosed golang.org/x/net/http2.errStreamClosed
|
||||||
|
var errStreamClosed error
|
||||||
|
|
||||||
func (p *ReverseProxy) errorHandler(rw http.ResponseWriter, r *http.Request, err error, writeHeader bool) {
|
func (p *ReverseProxy) errorHandler(rw http.ResponseWriter, r *http.Request, err error, writeHeader bool) {
|
||||||
reqURL := r.Host + r.URL.Path
|
reqURL := r.Host + r.URL.Path
|
||||||
switch {
|
switch {
|
||||||
@@ -186,6 +191,9 @@ func (p *ReverseProxy) errorHandler(rw http.ResponseWriter, r *http.Request, err
|
|||||||
log.Err(err).Msg("underlying error")
|
log.Err(err).Msg("underlying error")
|
||||||
goto logged
|
goto logged
|
||||||
}
|
}
|
||||||
|
if errors.Is(err, errStreamClosed) {
|
||||||
|
goto logged
|
||||||
|
}
|
||||||
var h2Err http2.StreamError
|
var h2Err http2.StreamError
|
||||||
if errors.As(err, &h2Err) {
|
if errors.As(err, &h2Err) {
|
||||||
// ignore these errors
|
// ignore these errors
|
||||||
|
|||||||
Reference in New Issue
Block a user