-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interoperability issues with reverse proxy (Transfer-Encoding: identity) #1909
Comments
I would be open to a pull request that stops fasthttp from returning an Identity encoding. |
@pflorczyk Thank you for reporting this issue. To help investigate and address the problem more efficiently, could you please provide a minimal, reproducible code example? |
Sorry for late response. package main
import (
"fmt"
"log"
"github.com/valyala/fasthttp"
)
func proxyHandler(ctx *fasthttp.RequestCtx) {
targetURL := "http://httpbin.org/stream/0"
req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)
req.Header.SetMethod(string(ctx.Method()))
req.SetRequestURI(targetURL)
req.Header.Set("User-Agent", string(ctx.Request.Header.UserAgent()))
resp := fasthttp.AcquireResponse()
defer fasthttp.ReleaseResponse(resp)
err := fasthttp.Do(req, resp)
if err != nil {
ctx.Error("Failed to proxy request", fasthttp.StatusInternalServerError)
return
}
fmt.Println("Response Headers from target server:")
resp.Header.VisitAll(func(key, value []byte) {
ctx.Response.Header.Set(string(key), string(value))
fmt.Printf("%s: %s\n", key, value)
})
ctx.Write(resp.Body())
}
func main() {
if err := fasthttp.ListenAndServe(":8080", proxyHandler); err != nil {
log.Fatalf("Error in ListenAndServe: %s", err)
}
} output from curl (headers copied from resp to ctx):
output from console (headers from resp):
This is my example code, not the one that triggers this issue. I guess the other team returns resp directly (to avoid copy). |
Recently we switched our reverse proxy servers to haproxy. Our users started reporting that they see increase in http 502 responses. After a bit of digging I was able to narrow it down to this on haproxy side:
This happens when client uses HEAD method, and there is no content-length set. fasthttp inserts
Transfer-Encoding: identity
into responses. I think the problem lies in ReadBody() function.It looks like "identity" has been deprecated for quite a long time (2008?):
https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.1
https://datatracker.ietf.org/doc/html/rfc9112#name-transfer-encoding
And here is related issue on haproxy side (they will not revert that change): haproxy/haproxy#2623
The text was updated successfully, but these errors were encountered: