Skip to content

Instantly share code, notes, and snippets.

@aavrug
Created July 12, 2020 17:16
Show Gist options
  • Save aavrug/6f6b2062bd573c29205fb2b728e7a6e2 to your computer and use it in GitHub Desktop.
Save aavrug/6f6b2062bd573c29205fb2b728e7a6e2 to your computer and use it in GitHub Desktop.
func sendRequest(w http.ResponseWriter, r *http.Request) {
url := r.URL
url.Host = "https://example.com/"
fmt.Println(url.String())
proxyReq, err := http.NewRequest(r.Method, url.String(), r.Body)
if err != nil {
fmt.Println(err)
}
proxyReq.Header.Set("Host", r.Host)
proxyReq.Header.Set("X-Forwarded-For", r.RemoteAddr)
for header, values := range r.Header {
for _, value := range values {
proxyReq.Header.Add(header, value)
}
}
client := &http.Client{}
proxyRes, err := client.Do(proxyReq)
if err != nil {
fmt.Println("Third party error")
}
fmt.Println(proxyRes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment