Skip to content

Instantly share code, notes, and snippets.

@airtonGit
Last active May 15, 2019 13:48
Show Gist options
  • Save airtonGit/601e60ee2dffc4d722009831eeda4a45 to your computer and use it in GitHub Desktop.
Save airtonGit/601e60ee2dffc4d722009831eeda4a45 to your computer and use it in GitHub Desktop.
Conceito basico de proxy reverso fornecido pela http lbrary na linguagem Go
func serveReverseProxy(target string, res http.ResponseWriter, req *http.Request) {
//parse the url
url, err := url.Parse(target)
if err != nil {
panic(err.Error())
}
//create de reverse proxy
proxy := httputil.NewSingleHostReverseProxy(url)
//Update the headers to allow for SSL redirection
req.URL.Host = url.Host
req.URL.Scheme = url.Scheme
req.Header.Set("X-Forwarded-Host", req.Header.Get("Host"))
req.Host = url.Host
// Note that ServeHttp is non blocking and uses a go routine under the hood
proxy.ServeHTTP(res, req)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment