MCPcopy
hub / github.com/caddyserver/caddy / cmdReverseProxy

Function cmdReverseProxy

modules/caddyhttp/reverseproxy/command.go:87–320  ·  view source on GitHub ↗
(fs caddycmd.Flags)

Source from the content-addressed store, hash-verified

85}
86
87func 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 }

Callers

nothing calls this directly

Calls 8

ParseAddressFunction · 0.92
JSONModuleObjectFunction · 0.92
JSONFunction · 0.92
parseUpstreamDialAddressFunction · 0.85
dialAddrMethod · 0.80
StringMethod · 0.45
BoolMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected