GitPedia

Fasthttp reverse proxy

reverse http / websocket proxy based on fasthttp

From yeqown·Updated May 23, 2026·View on GitHub·

- [x] `HTTP` reverse proxy based [fasthttp](https://github.com/valyala/fasthttp) The project is written primarily in Go, distributed under the MIT License license, first published in 2018. Key topics include: fasthttp, go, http-proxy, lib, reverse-proxy.

Latest release: v2.2.5
March 1, 2025View Changelog →

fasthttp-reverse-proxy

Go Report Card GoReportCard

reverse http proxy handler based on fasthttp.

Features

  • HTTP reverse proxy based fasthttp

    • it's faster than golang standard httputil.ReverseProxy library.
    • implemented by fasthttp.HostClient
    • support balance distribute based rounddobin
    • HostClient object pool with an overlay of fasthttp connection pool.
  • WebSocket reverse proxy.

Get started

HTTP (with balancer option)

go
var ( proxyServer = proxy.NewReverseProxy("localhost:8080") // use with balancer // weights = map[string]proxy.Weight{ // "localhost:8080": 20, // "localhost:8081": 30, // "localhost:8082": 50, // } // proxyServer = proxy.NewReverseProxy("", proxy.WithBalancer(weights)) ) // ProxyHandler ... fasthttp.RequestHandler func func ProxyHandler(ctx *fasthttp.RequestCtx) { // all proxy to localhost proxyServer.ServeHTTP(ctx) } func main() { if err := fasthttp.ListenAndServe(":8081", ProxyHandler); err != nil { log.Fatal(err) } }

Websocket

go
var ( proxyServer *proxy.WSReverseProxy once sync.Once ) // ProxyHandler ... fasthttp.RequestHandler func func ProxyHandler(ctx *fasthttp.RequestCtx) { once.Do(func() { var err error proxyServer, err = proxy.NewWSReverseProxyWith( proxy.WithURL_OptionWS("ws://localhost:8080/echo"), // [OPTIONAL]: you can override path from `WithURL_OptionWS` // by providing WithDynamicPath_OptionWS. proxy.WithDynamicPath_OptionWS(true, proxy.DefaultOverrideHeader), ) if err != nil { panic(err) } }) switch string(ctx.Path()) { case "/echo": // [OPTIONAL]: you can override path from `WithURL_OptionWS` // by providing proxy.DefaultOverrideHeader (or any custom) header // ctx.Request.Header.Set(proxy.DefaultOverrideHeader, "/real_echo") proxyServer.ServeHTTP(ctx) case "/": fasthttp.ServeFileUncompressed(ctx, "./index.html") default: ctx.Error("Unsupported path", fasthttp.StatusNotFound) } } func main() { log.Println("serving on: 8081") if err := fasthttp.ListenAndServe(":8081", ProxyHandler); err != nil { log.Fatal(err) } }

Usages

Contrast

References

Thanks

<a href="https://www.jetbrains.com/?from=fasthttp-reverse-proxy" _blank="#"> <img src="https://www.jetbrains.com/company/brand/img/jetbrains_logo.png" width="100" alt="JetBrains"/> </a>

Contributors

Showing top 9 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from yeqown/fasthttp-reverse-proxy via the GitHub API.Last fetched: 6/25/2026