Created
July 13, 2020 10:20
-
-
Save aavrug/7a7e8b9168e016301227e19d166c11c0 to your computer and use it in GitHub Desktop.
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 sendRequest(w http.ResponseWriter, r *http.Request) { | |
url := r.URL | |
url.Host = "todo.api.iriiis.com" | |
var buf bytes.Buffer | |
tee := io.TeeReader(r.Body, &buf) | |
proxyReq, err := http.NewRequest(r.Method, "https:"+url.String(), tee) | |
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) | |
fmt.Println(buf.String()) | |
if err != nil { | |
fmt.Println(err) | |
} | |
defer proxyRes.Body.Close() | |
fmt.Println("Header start") | |
fmt.Println(proxyRes.Header) | |
fmt.Println("Header end") | |
body, err := ioutil.ReadAll(proxyRes.Body) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Println(string(body)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment