summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/command.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-03-05 18:34:19 -0500
committerGitHub <noreply@github.com>2022-03-05 16:34:19 -0700
commitd058dee11d7cfcf0b711f0378d10c9e5cabc8982 (patch)
tree67cc4e1ddade57986340531497e7d45d82f82f43 /modules/caddyhttp/reverseproxy/command.go
parent09ba9e994e6391162fbfdfbd90c72270bdff3a49 (diff)
reverseproxy: Refactor dial address parsing, augment command parsing (#4616)
Diffstat (limited to 'modules/caddyhttp/reverseproxy/command.go')
-rw-r--r--modules/caddyhttp/reverseproxy/command.go27
1 files changed, 4 insertions, 23 deletions
diff --git a/modules/caddyhttp/reverseproxy/command.go b/modules/caddyhttp/reverseproxy/command.go
index 9bbc681..121142c 100644
--- a/modules/caddyhttp/reverseproxy/command.go
+++ b/modules/caddyhttp/reverseproxy/command.go
@@ -18,7 +18,6 @@ import (
"encoding/json"
"flag"
"fmt"
- "net"
"net/http"
"strconv"
@@ -104,32 +103,14 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
}
// set up the upstream address; assume missing information from given parts
- toAddr, err := httpcaddyfile.ParseAddress(to)
+ toAddr, toScheme, err := parseUpstreamDialAddress(to)
if err != nil {
return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid upstream address %s: %v", to, err)
}
- if toAddr.Path != "" {
- return caddy.ExitCodeFailedStartup, fmt.Errorf("paths are not allowed: %s", to)
- }
- if toAddr.Scheme == "" {
- if toAddr.Port == httpsPort {
- toAddr.Scheme = "https"
- } else {
- toAddr.Scheme = "http"
- }
- }
- if toAddr.Port == "" {
- if toAddr.Scheme == "http" {
- toAddr.Port = httpPort
- } else if toAddr.Scheme == "https" {
- toAddr.Port = httpsPort
- }
- }
// proceed to build the handler and server
-
ht := HTTPTransport{}
- if toAddr.Scheme == "https" {
+ if toScheme == "https" {
ht.TLS = new(TLSConfig)
if insecure {
ht.TLS.InsecureSkipVerify = true
@@ -138,7 +119,7 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
handler := Handler{
TransportRaw: caddyconfig.JSONModuleObject(ht, "protocol", "http", nil),
- Upstreams: UpstreamPool{{Dial: net.JoinHostPort(toAddr.Host, toAddr.Port)}},
+ Upstreams: UpstreamPool{{Dial: toAddr}},
}
if changeHost {
@@ -185,7 +166,7 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
return caddy.ExitCodeFailedStartup, err
}
- fmt.Printf("Caddy proxying %s -> %s\n", fromAddr.String(), toAddr.String())
+ fmt.Printf("Caddy proxying %s -> %s\n", fromAddr.String(), toAddr)
select {}
}