@marcel91200 / caddy Mirror · read-only / commits / cb25dd72
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

reverse_proxy: Add port to upstream address if only implied in scheme

Matthew Holt committed Nov 4, 2019 at 12:18 UTC cb25dd72abec854b359ca8194cb07b2571d950d4
1 file changed +9
modules/caddyhttp/reverseproxy/command.go
+9
@@ -18,6 +18,7 @@ import (
18 "encoding/json"
19 "flag"
20 "fmt"
21 + "net"
22 "net/http"
23 "net/url"
24 "strings"
@@ -80,6 +81,14 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
81 return caddy.ExitCodeFailedStartup, fmt.Errorf("parsing 'to' URL: %v", err)
82 }
83
84 + if toURL.Port() == "" {
85 + toPort := "80"
86 + if toURL.Scheme == "https" {
87 + toPort = "443"
88 + }
89 + toURL.Host = net.JoinHostPort(toURL.Host, toPort)
90 + }
91 +
92 ht := HTTPTransport{}
93 if toURL.Scheme == "https" {
94 ht.TLS = new(TLSConfig)