Skip to content
This repository was archived by the owner on Feb 20, 2021. It is now read-only.

Repository files navigation

Moxy - A multi-host reverse proxy for golang

Build Status

The stdlib ReverseProxy from net/http/httputil has 2 issues that this project solves

  1. There is single host proxy provided by NewSingleHostReverseProxy, but there is nothing to create a multi-host proxy
  2. While it's possible to process a request before sending it to the proxy, the standard proxy doesn't provide a way to process the proxy response before flushing it out to the clients.

moxy aims to solve both of these problems by

  1. Providing moxy.NewReverseProxy, that supports load-balancing across multiple hosts
  2. Adding suppport for moxy.FilterFunc, a chain of functions that run over the proxy response & optionally make changes to it, before sending it back to the clients.

Example (using negroni)

package main
import (
"github.com/codegangsta/negroni""github.com/gorilla/mux""github.com/wunderlist/moxy""net/http"
)
funcAddSecurityHeaders(request*http.Request, response*http.Response) {
response.Header.Del("X-Powered-By")
response.Header.Set("X-Super-Secure", "Yes!!")
}
funcmain() {
hosts:= []string{"dynamic.host.com"}
filters:= []moxy.FilterFunc{AddSecurityHeaders}
proxy:=moxy.NewReverseProxy(hosts, filters)
router:=mux.NewRouter()
router.HandleFunc("/resource1", proxy.ServeHTTP)
router.HandleFunc("/resource2", proxy.ServeHTTP)
app:=negroni.New()
app.UseHandler(router)
app.Run(":3009")
}

About

a multi-host reverse proxy for golang

Topics

Resources

Stars

33 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages