summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorKarun Agarwal <113603846+singhalkarun@users.noreply.github.com>2023-08-19 16:58:25 +0530
committerGitHub <noreply@github.com>2023-08-19 07:28:25 -0400
commit288216e1fbf25ebe11fcea7c71be526c4cd0dcce (patch)
treed5218fe1f29c39f6c5f006b9706f4263f3d88fb3 /modules/caddyhttp
parent10053f7570b113d41c5a5ba40e6c457ab0784ef5 (diff)
httpcaddyfile: Stricter errors for site and upstream address schemes (#5757)
Co-authored-by: Mohammed Al Sahaf <msaa1990@gmail.com> Co-authored-by: Francis Lavoie <lavofr@gmail.com>
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/reverseproxy/caddyfile.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go
index a986f89..674776f 100644
--- a/modules/caddyhttp/reverseproxy/caddyfile.go
+++ b/modules/caddyhttp/reverseproxy/caddyfile.go
@@ -155,6 +155,18 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// the underlying JSON does not yet support different
// transports (protocols or schemes) to each backend,
// so we remember the last one we see and compare them
+
+ switch pa.scheme {
+ case "wss":
+ return d.Errf("the scheme wss:// is only supported in browsers; use https:// instead")
+ case "ws":
+ return d.Errf("the scheme ws:// is only supported in browsers; use http:// instead")
+ case "https", "http", "h2c", "":
+ // Do nothing or handle the valid schemes
+ default:
+ return d.Errf("unsupported URL scheme %s://", pa.scheme)
+ }
+
if commonScheme != "" && pa.scheme != commonScheme {
return d.Errf("for now, all proxy upstreams must use the same scheme (transport protocol); expecting '%s://' but got '%s://'",
commonScheme, pa.scheme)
@@ -193,7 +205,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for _, up := range d.RemainingArgs() {
err := appendUpstream(up)
if err != nil {
- return err
+ return fmt.Errorf("parsing upstream '%s': %w", up, err)
}
}
@@ -217,7 +229,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for _, up := range args {
err := appendUpstream(up)
if err != nil {
- return err
+ return fmt.Errorf("parsing upstream '%s': %w", up, err)
}
}