package main import ( "fmt" "net/http" "net/http/httputil" "net/url" ) func fetchHandler(w http.ResponseWriter, r *http.Request) { path := r.URL.Path path = fmt.Sprintf("https://secure.gravatar.com%s", path) fmt.Println("need reverse url: ", path) rpURL, _ := url.Parse(path) proxy := httputil.NewSingleHostReverseProxy(rpURL) director := proxy.Director proxy.Director = func(r *http.Request) { director(r) r.Host = "secure.gravatar.com" } proxy.ServeHTTP(w, r) } func main() { http.HandleFunc("/", fetchHandler) err := http.ListenAndServe(fmt.Sprintf(":%d", 80), nil) if err != nil { fmt.Println("run server error: ", err) return } }