// source code: net/http/httputil/reverseproxy.go err = p.copyResponse(rw, res.Body, p.flushInterval(res)) if err != nil { defer res.Body.Close() // Since we're streaming the response, if we run into an error all we can do // is abort the request. Issue 23643: ReverseProxy should use ErrAbortHandler // on read error while copying body. if !shouldPanicOnCopyError(req) { p.logf("suppressing panic for copyResponse error in test; copy error: %v", err) return } panic(http.ErrAbortHandler) }
解决方法,加一层recover拦截
1 2 3 4 5 6 7 8 9 10
deferfunc() { if err := recover(); err != nil { if err == http.ErrAbortHandler { return }