fasthttp
fasthttp copied to clipboard
Reverse Proxy : fasthttp.HostClient crash
import (
"github.com/valyala/fasthttp"
)
var proxyClient = &fasthttp.HostClient{
Addr: "upstream.host:port",
// set other options here if required - most notably timeouts.
}
func ReverseProxyHandler(ctx *fasthttp.RequestCtx) {
req := &ctx.Request
resp := &ctx.Response
prepareRequest(req)
if err := proxyClient.Do(req, resp); err != nil {
ctx.Logger().Printf("error when proxying the request: %s", err)
}
postprocessResponse(resp)
}
func prepareRequest(req *fasthttp.Request) {
// do not proxy "Connection" header.
req.Header.Del("Connection")
// strip other unneeded headers.
// alter other request params before sending them to upstream host
// req.SetHost(upstream.host)
}
func postprocessResponse(resp *fasthttp.Response) {
// do not proxy "Connection" header
resp.Header.Del("Connection")
// strip other unneeded headers
// alter other response data if needed
}
func main() {
if err := fasthttp.ListenAndServe(":8080", reverseProxyHandler); err != nil {
log.Fatalf("error in fasthttp server: %s", err)
}
}
fasthttp.HostClient Do (function): Crash when forwarding big file (> 2GB)
Can we get a stack trace or an error message?