diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-27 09:26:30 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-27 09:26:30 -0600 |
| commit | 6f46dbe906a4c1ea1d2616a9b84f29bbddb33719 (patch) | |
| tree | 6ca8591a0cfe01fe4eb3bda436b566a727a29735 /pkg | |
| parent | f7b7b7702ef5821f150481221fd71b256b845096 (diff) | |
refactor: use proxy request to add forwarded headers
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/prxy/prxy.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/pkg/prxy/prxy.go b/pkg/prxy/prxy.go index 0e6e8c31..1e378b3d 100644 --- a/pkg/prxy/prxy.go +++ b/pkg/prxy/prxy.go @@ -18,17 +18,16 @@ func New(routes map[string]string) http.Handler { } return &httputil.ReverseProxy{ - Director: func(r *http.Request) { - host, _, err := net.SplitHostPort(r.Host) + Rewrite: func(r *httputil.ProxyRequest) { + host, _, err := net.SplitHostPort(r.In.Host) if err != nil { - fmt.Printf("%v\n", err) + log.Println(err) return } destination := mapped[host] - r.URL.Scheme = destination.Scheme - r.Host = destination.Host - r.URL.Host = destination.Host + r.SetXForwarded() + r.SetURL(destination) }, Transport: http.DefaultTransport, FlushInterval: -1, |
