Skip to content

Commit

Permalink
Make it possible to proxy through a Unix domain socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
pyama86 committed Nov 24, 2023
1 parent f804e59 commit 88e3ac0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
)

const errorKey = "X-Proxy-Error"
Expand Down Expand Up @@ -73,7 +74,11 @@ func NewRouter(r Relayer) http.Handler {
return
}
if u != nil {
pr.Out.Host = u.Host
if strings.HasPrefix(u.Host, "/") {
pr.Out.Host = pr.In.Host
} else {
pr.Out.Host = u.Host
}
pr.Out.URL = u
pr.SetXForwarded()
}
Expand All @@ -89,9 +94,13 @@ func NewRouter(r Relayer) http.Handler {
return
}
if u != nil {
pr.Out.Host = u.Host
pr.Out.URL = u
if strings.HasPrefix(u.Host, "/") {
pr.Out.Host = pr.In.Host
} else {
pr.Out.Host = u.Host
}

pr.Out.URL = u
}
if err := rr.Rewrite(pr); err != nil {
pr.Out.Header.Set(errorKey, err.Error())
Expand Down

0 comments on commit 88e3ac0

Please sign in to comment.