proxyRequest with ClientAddress and not localhost

This commit is contained in:
Willem@105.pve1.lan 2022-02-14 17:38:52 +02:00
parent 02dda12e0e
commit 7d740b7c31
3 changed files with 4 additions and 6 deletions

View File

@ -274,7 +274,7 @@ func Listen() {
return
}
proxyRequest(w, r, tunnel, httpClient, tunnel.TunnelPort, *behindProxy)
proxyRequest(w, r, tunnel, httpClient, "localhost", tunnel.TunnelPort, *behindProxy)
}
})

View File

@ -297,7 +297,7 @@ func (c *Client) BoreTunnel(ctx context.Context, tunnel Tunnel) error {
httpMux := http.NewServeMux()
httpMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
proxyRequest(w, r, tunnel, c.httpClient, tunnel.ClientPort, c.behindProxy)
proxyRequest(w, r, tunnel, c.httpClient, tunnel.ClientAddress, tunnel.ClientPort, c.behindProxy)
})
httpServer := &http.Server{

View File

@ -8,7 +8,7 @@ import (
"time"
)
func proxyRequest(w http.ResponseWriter, r *http.Request, tunnel Tunnel, httpClient *http.Client, port int, behindProxy bool) {
func proxyRequest(w http.ResponseWriter, r *http.Request, tunnel Tunnel, httpClient *http.Client, address string, port int, behindProxy bool) {
if tunnel.AuthUsername != "" || tunnel.AuthPassword != "" {
username, password, ok := r.BasicAuth()
@ -29,9 +29,7 @@ func proxyRequest(w http.ResponseWriter, r *http.Request, tunnel Tunnel, httpCli
downstreamReqHeaders := r.Header.Clone()
// TODO: should probably pass in address instead of using localhost,
// mostly for client-terminated TLS
upstreamAddr := fmt.Sprintf("localhost:%d", port)
upstreamAddr := fmt.Sprintf("%s:%d", address, port)
upstreamUrl := fmt.Sprintf("http://%s%s", upstreamAddr, r.URL.RequestURI())
upstreamReq, err := http.NewRequest(r.Method, upstreamUrl, r.Body)