Last active
May 15, 2019 13:48
-
-
Save airtonGit/601e60ee2dffc4d722009831eeda4a45 to your computer and use it in GitHub Desktop.
Conceito basico de proxy reverso fornecido pela http lbrary na linguagem Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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