Created
July 12, 2020 20:23
-
-
Save aavrug/e6db309871fa0d8a20915130235e98bd to your computer and use it in GitHub Desktop.
This file contains 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 sendRequest(w http.ResponseWriter, r *http.Request) { | |
url := r.URL | |
url.Host = "example.com" | |
proxyReq, err := http.NewRequest(r.Method, "https:"+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(err) | |
} | |
defer proxyRes.Body.Close() | |
var buf bytes.Buffer | |
io.TeeReader(proxyRes.Body, &buf) | |
fmt.Println(buf.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment