I am trying to do it to dump the response of an HTTP GET request and write the very same response in an http.ResponseWriter
. Here is my code:
package main
import (
"net/http"
"net/http/httputil"
)
func handler(w http.ResponseWriter, r *http.Request) {
resp, _ := http.Get("http://google.com")
dump, _ := httputil.DumpResponse(resp,true)
w.Write(dump)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
I get a full page of HTML code of google.com instead of the Google front page. Is there a way I can achieve a proxy-like effect?
w
not the whole response(http headers + body):body, _ := ioutil.ReadAll(resp.Body); w.Write(body)
. – Repression