summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/hosts.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/reverseproxy/hosts.go')
-rw-r--r--modules/caddyhttp/reverseproxy/hosts.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/caddyhttp/reverseproxy/hosts.go b/modules/caddyhttp/reverseproxy/hosts.go
index 1c0fae3..a8349bd 100644
--- a/modules/caddyhttp/reverseproxy/hosts.go
+++ b/modules/caddyhttp/reverseproxy/hosts.go
@@ -16,6 +16,8 @@ package reverseproxy
import (
"fmt"
+ "net"
+ "strings"
"sync/atomic"
"github.com/caddyserver/caddy/v2"
@@ -173,6 +175,27 @@ type DialInfo struct {
// The address to dial. Follows the same
// semantics and rules as net.Dial.
Address string
+
+ // Host and Port are components of Address,
+ // pre-split for convenience.
+ Host, Port string
+}
+
+// NewDialInfo creates and populates a DialInfo
+// for the given network and address. It splits
+// the address into host and port values if the
+// network type supports them, or uses the whole
+// address as the port if splitting fails.
+func NewDialInfo(network, address string) DialInfo {
+ var addrHost, addrPort string
+ if !strings.Contains(network, "unix") {
+ var err error
+ addrHost, addrPort, err = net.SplitHostPort(address)
+ if err != nil {
+ addrHost = address // assume there was no port
+ }
+ }
+ return DialInfo{network, address, addrHost, addrPort}
}
// String returns the Caddy network address form