Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Index out of range error when using {block} #7518

@ZingyAwesome

Description

@ZingyAwesome

Issue Details

Now that Caddy 2.11 has been released with #7206 merged, I hoped to use the block feature like so:
In snippets.conf:

(reverse_proxy) {
  reverse_proxy {args[:]} {
    header_up X-Forwarded-For {client_ip}
    {block}
  }
}

In sites.conf:

subdomain.mydomain.com {
  import reverse_proxy container_name:8080
}

subdomain2.mydomain.com {
  import reverse_proxy container2_name:8080 {
    # Some option I want to pass to reverse_proxy, e.g.
    header_up SomeHeader SomeValue
  }
}

However when starting caddy, I get the following error. Removing {block} from the snippet gets rid of the error, but if I do this then I cannot pass additional options to reverse_proxy which is not ideal.

panic: runtime error: index out of range [41] with length 41

goroutine 1 [running]:
github.com/caddyserver/caddy/v2/caddyconfig/caddyfile.(*parser).doImport(0x422d145833b8, 0x0)
	github.com/caddyserver/caddy/[email protected]/caddyconfig/caddyfile/parse.go:510 +0x1b38
github.com/caddyserver/caddy/v2/caddyconfig/caddyfile.(*parser).addresses(0x422d145833b8)
	github.com/caddyserver/caddy/[email protected]/caddyconfig/caddyfile/parse.go:224 +0x340
github.com/caddyserver/caddy/v2/caddyconfig/caddyfile.(*parser).begin(0x422d145833b8)
	github.com/caddyserver/caddy/[email protected]/caddyconfig/caddyfile/parse.go:151 +0x34
github.com/caddyserver/caddy/v2/caddyconfig/caddyfile.(*parser).parseOne(...)
	github.com/caddyserver/caddy/[email protected]/caddyconfig/caddyfile/parse.go:143
github.com/caddyserver/caddy/v2/caddyconfig/caddyfile.(*parser).parseAll(0x422d145833b8)
	github.com/caddyserver/caddy/[email protected]/caddyconfig/caddyfile/parse.go:126 +0xb0
github.com/caddyserver/caddy/v2/caddyconfig/caddyfile.Parse({0xffffe175ce2e, 0x14}, {0x422d13fb1b00, 0x405, 0x108?})
	github.com/caddyserver/caddy/[email protected]/caddyconfig/caddyfile/parse.go:57 +0x104
github.com/caddyserver/caddy/v2/caddyconfig/caddyfile.Adapter.Adapt({{0x1adcba0?, 0x2dd0820?}}, {0x422d13fb1b00, 0x405, 0x406}, 0x422d13f56d20?)
	github.com/caddyserver/caddy/[email protected]/caddyconfig/caddyfile/adapter.go:45 +0xc4
github.com/caddyserver/caddy/v2/cmd.loadConfigWithLogger(0x422d145838f8?, {0xffffe175ce2e, 0x14}, {0x0, 0x0})
	github.com/caddyserver/caddy/[email protected]/cmd/main.go:212 +0x82c
github.com/caddyserver/caddy/v2/cmd.LoadConfig({0xffffe175ce2e, 0x14}, {0x0, 0x0})
	github.com/caddyserver/caddy/[email protected]/cmd/main.go:109 +0x40
github.com/caddyserver/caddy/v2/cmd.cmdReload({0x0?})
	github.com/caddyserver/caddy/[email protected]/cmd/commandfuncs.go:367 +0xb0
github.com/caddyserver/caddy/v2/cmd.init.1.func4.WrapCommandFuncForCobra.1(0x422d14112c08, {0x1761fb2?, 0x4?, 0x1761f76?})
	github.com/caddyserver/caddy/[email protected]/cmd/cobra.go:141 +0x34
github.com/spf13/cobra.(*Command).execute(0x422d14112c08, {0x422d144af300, 0x2, 0x2})
	github.com/spf13/[email protected]/command.go:1015 +0x814
github.com/spf13/cobra.(*Command).ExecuteC(0x422d1420f808)
	github.com/spf13/[email protected]/command.go:1148 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:1071
github.com/caddyserver/caddy/v2/cmd.Main()
	github.com/caddyserver/caddy/[email protected]/cmd/main.go:72 +0x6c
main.main()
	caddy/main.go:17 +0x1c

Assistance Disclosure

AI not used

If AI was used, describe the extent to which it was used.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞Something isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions