Skip to content

Commit

Permalink
fix: unix sock path trimming on go 1.19+
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemmmy committed Feb 9, 2024
1 parent 65fd4af commit 518dcf0
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions caskethttp/proxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,9 @@ type ReverseProxy struct {
srvResolver srvResolver
}

// Though the relevant directive prefix is just "unix:", url.Parse
// will - assuming the regular URL scheme - add additional slashes
// as if "unix" was a request protocol.
// What we need is just the path, so if "unix:/var/run/www.socket"
// was the proxy directive, the parsed hostName would be
// "unix:///var/run/www.socket", hence the ambiguous trimming.
func socketDial(hostName string, timeout time.Duration) func(network, addr string) (conn net.Conn, err error) {
return func(network, addr string) (conn net.Conn, err error) {
return net.DialTimeout("unix", hostName[len("unix://"):], timeout)
return net.DialTimeout("unix", hostName[len("unix:"):], timeout)
}
}

Expand Down Expand Up @@ -216,8 +210,7 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int, t
// unix:/var/run/www.socket will thus set the requested path
// to /var/run/www.socket/test, rendering paths useless.
if target.Scheme == "unix" {
// See comment on socketDial for the trim
socketPrefix := target.String()[len("unix://"):]
socketPrefix := target.String()[len("unix:"):]
req.URL.Path = strings.TrimPrefix(req.URL.Path, socketPrefix)
if req.URL.Opaque != "" {
req.URL.Opaque = strings.TrimPrefix(req.URL.Opaque, socketPrefix)
Expand Down

0 comments on commit 518dcf0

Please sign in to comment.