forked from caddyserver/caddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Go 1.19 compatibility for unix socket reverse proxy URLs
Since Go 1.19 the net/url URL.Parse function is changed when there is no host authority. This change broke the unix socket URL handling in the reverse proxy code. This change adds auto detection for the behavior and thus supports both old and new Go versions without having to add build constraints. Related: golang/go#46059
- Loading branch information
Showing
2 changed files
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package proxy | ||
|
||
import ( | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
// unixProtocolPrefixLength defines the length of the prefix of parsed URLs | ||
// starting with unix: scheme. The actual value is different since Go 1.19 where | ||
// the prefix no longer contains a // as unix: is not a registered scheme. | ||
// See https://github.com/golang/go/commit/ab0f7611d739fe10d0265dbc6bdc17684423bfc8 | ||
// for reference. | ||
var unixProtocolPrefixLength = func() int { | ||
u, _ := url.Parse("unix:/some/path") | ||
|
||
if strings.HasPrefix(u.String(), "unix://") { | ||
// For Go < 1.19 url parse generates strings with an injected //. | ||
return len("unix://") | ||
} | ||
return len("unix:") | ||
}() |