mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 21:10:51 +08:00
fix(amp): suppress ErrAbortHandler panics in reverse proxy handler
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package amp
|
package amp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
@@ -113,6 +114,17 @@ func (m *AmpModule) registerManagementRoutes(engine *gin.Engine, baseHandler *ha
|
|||||||
|
|
||||||
// Dynamic proxy handler that uses m.getProxy() for hot-reload support
|
// Dynamic proxy handler that uses m.getProxy() for hot-reload support
|
||||||
proxyHandler := func(c *gin.Context) {
|
proxyHandler := func(c *gin.Context) {
|
||||||
|
// Swallow ErrAbortHandler panics from ReverseProxy copyResponse to avoid noisy stack traces
|
||||||
|
defer func() {
|
||||||
|
if rec := recover(); rec != nil {
|
||||||
|
if err, ok := rec.(error); ok && errors.Is(err, http.ErrAbortHandler) {
|
||||||
|
// Upstream already wrote the status (often 404) before the client/stream ended.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
panic(rec)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
proxy := m.getProxy()
|
proxy := m.getProxy()
|
||||||
if proxy == nil {
|
if proxy == nil {
|
||||||
c.JSON(503, gin.H{"error": "amp upstream proxy not available"})
|
c.JSON(503, gin.H{"error": "amp upstream proxy not available"})
|
||||||
|
|||||||
Reference in New Issue
Block a user