summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/addresses.go
diff options
context:
space:
mode:
authorSteffen Brüheim <ueffel@gmail.com>2023-02-08 18:05:09 +0100
committerGitHub <noreply@github.com>2023-02-08 10:05:09 -0700
commit536c28d4dc4b048d710bd37903857f0de15ab3c5 (patch)
tree4107376cdb131592cb2e417bb54b65a8f2531e67 /modules/caddyhttp/reverseproxy/addresses.go
parentc77a6bea66b30ea88cd991671bf67669c80ffcdd (diff)
core: Support Windows absolute paths for UDS proxy upstreams (#5114)
* added some tests for parseUpstreamDialAddress Test 4 fails because it produces "[[::1]]:80" instead of "[::1]:80" * support absolute windows path in unix reverse proxy address * make IsUnixNetwork public, support +h2c and reuse it * add new tests
Diffstat (limited to 'modules/caddyhttp/reverseproxy/addresses.go')
-rw-r--r--modules/caddyhttp/reverseproxy/addresses.go12
1 files changed, 2 insertions, 10 deletions
diff --git a/modules/caddyhttp/reverseproxy/addresses.go b/modules/caddyhttp/reverseproxy/addresses.go
index 4da47fb..8152108 100644
--- a/modules/caddyhttp/reverseproxy/addresses.go
+++ b/modules/caddyhttp/reverseproxy/addresses.go
@@ -27,9 +27,6 @@ import (
// the dial address, including support for a scheme in front
// as a shortcut for the port number, and a network type,
// for example 'unix' to dial a unix socket.
-//
-// TODO: the logic in this function is kind of sensitive, we
-// need to write tests before making any more changes to it
func parseUpstreamDialAddress(upstreamAddr string) (string, string, error) {
var network, scheme, host, port string
@@ -79,19 +76,14 @@ func parseUpstreamDialAddress(upstreamAddr string) (string, string, error) {
scheme, host, port = toURL.Scheme, toURL.Hostname(), toURL.Port()
} else {
- // extract network manually, since caddy.ParseNetworkAddress() will always add one
- if beforeSlash, afterSlash, slashFound := strings.Cut(upstreamAddr, "/"); slashFound {
- network = strings.ToLower(strings.TrimSpace(beforeSlash))
- upstreamAddr = afterSlash
- }
var err error
- host, port, err = net.SplitHostPort(upstreamAddr)
+ network, host, port, err = caddy.SplitNetworkAddress(upstreamAddr)
if err != nil {
host = upstreamAddr
}
// we can assume a port if only a hostname is specified, but use of a
// placeholder without a port likely means a port will be filled in
- if port == "" && !strings.Contains(host, "{") {
+ if port == "" && !strings.Contains(host, "{") && !caddy.IsUnixNetwork(network) {
port = "80"
}
}