[BUG] proxy chunked enconding upstream erase body when record is active
- Dominant language
- Go
- Stars
- 25.6k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I setup a chunked encoding response http server at localhost:9394, and try use host.ProxyHandle to proxy it when ctx.Record() is call in middleware, that lead to body be erased.
**To Reproduce**
Steps to reproduce the behavior:
```go
package main
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/core/host"
"net/http"
"net/http/httputil"
"net/url"
)
func recorder(ctx *context.Context) {
if _, ok := ctx.IsRecording(); !ok {
ctx.Record()
}
ctx.Next()
}
func main() {
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
chunkedWriter := httputil.NewChunkedWriter(writer)
writer.Header().Set("Transfer-Encoding", "chunked")
chunkedWriter.Write([]byte("hello"))
chunkedWriter.Close()
})
go http.ListenAndServe(":9394", nil)
app := iris.New()
app.Use(recorder)
u, _ := url.Parse("http://localhost:9394")
app.Get("/", iris.FromStd(host.ProxyHandler(u, nil)))
app.Run(iris.Addr(":9395"))
}
```
**Expected behavior**
body response to client as normal
**iris.Version**
- v12.1.8
- go 1.16.4
Please make sure the bug is reproducible over the `master` branch:
```sh
$ cd PROJECT
$ go get -u github.com/kataras/iris/v12@master
$ go run .
```
**Additional context**
a quick workaround is supply ModifyResponse to httputil.ReverseProxy, modify response.ContentLength to 0 when it's -1.
(http.ReverseProxy will not call ResponseWriter.Flush in this situation)
Contributor guide
Assessment
This issue has not been assessed yet.