diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-09-14 13:25:26 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-09-14 13:25:26 -0600 |
commit | e73b117332a5606a986ee7e03e6f4b0cea7871c9 (patch) | |
tree | e2819a50e4bfdab7d0d1511bc433b1b41e403da2 /modules/caddyhttp/reverseproxy/hosts.go | |
parent | 2fd22139c6b7b6055ae53c77d56278fce38d1195 (diff) |
reverse_proxy: Ability to mutate headers; set upstream placeholders
Diffstat (limited to 'modules/caddyhttp/reverseproxy/hosts.go')
-rw-r--r-- | modules/caddyhttp/reverseproxy/hosts.go | 23 |
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 |