package main
import (
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
target := &url.URL{Scheme: "http", Host: "www.google.com"}
proxy := httputil.NewSingleHostReverseProxy(target)
http.Handle("/google", proxy)
http.ListenAndServe(":8099", nil)
}
Reverse Proxy is works. How can I get the response body?
I don't know best solution. But you can do something like this:
now httputil/reverseproxy, support than, see source
httputil.ReverseProxy
has aTransport
field. You can use it to modify the response. For example:Playground example of the whole thing: http://play.golang.org/p/b0S5CbCMrI.