Skip to content
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

Reverse Proxy : fasthttp.HostClient crash #1587

Open
linuxpham opened this issue Jul 3, 2023 · 1 comment
Open

Reverse Proxy : fasthttp.HostClient crash #1587

linuxpham opened this issue Jul 3, 2023 · 1 comment

Comments

@linuxpham
Copy link

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)

@erikdubbelboer
Copy link
Collaborator

Can we get a stack trace or an error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants