You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
u, _ := url.Parse("http://localhost:8002/";)
go http.ListenAndServe(":8002", http.HandlerFunc(echo))
log.Fatal(http.ListenAndServe(":8001", httputil.NewSingleHostReverseProxy(u)))
}
func echo(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
req.Write(w)
}
There is an echo server running on http://localhost:8002/
that prints the request back, and a proxy on http://localhost:8001/
that proxies to http://localhost:8002/.
I expect that loading either port should be the same, but they're not.
coma=; curl http://localhost:8001/
GET / HTTP/1.1
Host: localhost:8001
User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4
libidn/1.18
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: ::1
coma=; curl http://localhost:8002/
GET / HTTP/1.1
Host: localhost:8002
User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4
libidn/1.18
Accept: */*
coma=;
Remember that the 8002 server is echoing back the request
in both cases. In the proxying (first) case, the proxied
request still says Host: localhost:8001. That seems wrong.
The text was updated successfully, but these errors were encountered:
It is called a *reverse* proxy. In that direction, Host is typically not fixed up.
Reverse proxies are used to take requests from the Internet and balance them over many
backend servers, which will want to know the original host.
I don't know the context here, but it sounds like you want an outbound proxy.
Hopefully I'm using the right terminology, if there are naming rules for any of this.
The text was updated successfully, but these errors were encountered: