improve reverse proxy and serverhandling

- buffer pool for IO copy
  - flush response after read, now works with event stream
  - fixed error handling for server
This commit is contained in:
yusing
2025-02-13 18:39:35 +08:00
parent 6bf4846ae8
commit 19e3392825
7 changed files with 132 additions and 116 deletions

View File

@@ -410,15 +410,13 @@ func (p *ReverseProxy) handler(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(res.StatusCode)
_, err = io.Copy(rw, res.Body)
err = U.CopyClose(U.NewContextWriter(ctx, rw), U.NewContextReader(ctx, res.Body)) // close now, instead of defer, to populate res.Trailer
if err != nil {
if !errors.Is(err, context.Canceled) {
p.errorHandler(rw, req, err, true)
}
res.Body.Close()
return
}
res.Body.Close() // close now, instead of defer, to populate res.Trailer
if len(res.Trailer) > 0 {
// Force chunking if we saw a response trailer.