(fs caddycmd.Flags)
| 85 | } |
| 86 | |
| 87 | func cmdReverseProxy(fs caddycmd.Flags) (int, error) { |
| 88 | caddy.TrapSignals() |
| 89 | |
| 90 | from := fs.String("from") |
| 91 | changeHost := fs.Bool("change-host-header") |
| 92 | insecure := fs.Bool("insecure") |
| 93 | disableRedir := fs.Bool("disable-redirects") |
| 94 | internalCerts := fs.Bool("internal-certs") |
| 95 | accessLog := fs.Bool("access-log") |
| 96 | debug := fs.Bool("debug") |
| 97 | |
| 98 | httpPort := strconv.Itoa(caddyhttp.DefaultHTTPPort) |
| 99 | httpsPort := strconv.Itoa(caddyhttp.DefaultHTTPSPort) |
| 100 | |
| 101 | to, err := fs.GetStringSlice("to") |
| 102 | if err != nil { |
| 103 | return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid to flag: %v", err) |
| 104 | } |
| 105 | if len(to) == 0 { |
| 106 | return caddy.ExitCodeFailedStartup, fmt.Errorf("--to is required") |
| 107 | } |
| 108 | |
| 109 | // set up the downstream address; assume missing information from given parts |
| 110 | fromAddr, err := httpcaddyfile.ParseAddress(from) |
| 111 | if err != nil { |
| 112 | return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid downstream address %s: %v", from, err) |
| 113 | } |
| 114 | if fromAddr.Path != "" { |
| 115 | return caddy.ExitCodeFailedStartup, fmt.Errorf("paths are not allowed: %s", from) |
| 116 | } |
| 117 | if fromAddr.Scheme == "" { |
| 118 | if fromAddr.Port == httpPort || fromAddr.Host == "" { |
| 119 | fromAddr.Scheme = "http" |
| 120 | } else { |
| 121 | fromAddr.Scheme = "https" |
| 122 | } |
| 123 | } |
| 124 | if fromAddr.Port == "" { |
| 125 | switch fromAddr.Scheme { |
| 126 | case "http": |
| 127 | fromAddr.Port = httpPort |
| 128 | case "https": |
| 129 | fromAddr.Port = httpsPort |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // set up the upstream address; assume missing information from given parts |
| 134 | // mixing schemes isn't supported, so use first defined (if available) |
| 135 | toAddresses := make([]string, len(to)) |
| 136 | var toScheme string |
| 137 | for i, toLoc := range to { |
| 138 | addr, err := parseUpstreamDialAddress(toLoc) |
| 139 | if err != nil { |
| 140 | return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid upstream address %s: %v", toLoc, err) |
| 141 | } |
| 142 | if addr.scheme != "" && toScheme == "" { |
| 143 | toScheme = addr.scheme |
| 144 | } |
nothing calls this directly
no test coverage detected