Repository: caddyserver/caddy (language: go)

Issue:
Parsing error with new `protocols` directive
The new `protocols` subdirective in `servers` is only excepted when it is the last directive in the `servers` block. Is that intended?

Example Caddyfile:

```caddy-d
{
	servers :443 {
		protocols h1 h2 h3
		strict_sni_host insecure_off
	}
}
```

or

```caddy-d
{
	servers :443 {
		protocols h1 h2 h3
		log_credentials
	}
}
```

Produces errors:

```plain
Error: adapting config using caddyfile: parsing caddyfile tokens for 'servers': Caddyfile:4 - Error during parsing: Wrong argument count or unexpected line ending after 'strict_sni_host'
```

```plain
Error: adapting config using caddyfile: parsing caddyfile tokens for 'servers': Caddyfile:4 - Error during parsing: Wrong argument count or unexpected line ending after 'log_credentials'
```

This works though:

```caddy-d
{
	servers :443 {
		log_credentials
		protocols h1 h2 h3
	}
}
```

Related pull request: https://github.com/caddyserver/caddy/pull/4707

Tested version: v2.6.0-beta.5


Discussion / hints:
Yep, I see the issue. Thanks! Pushing a fix in a sec.

Fix patch:
diff --git a/caddyconfig/httpcaddyfile/serveroptions.go b/caddyconfig/httpcaddyfile/serveroptions.go
index 8e021fd5d81..8ab8969de31 100644
--- a/caddyconfig/httpcaddyfile/serveroptions.go
+++ b/caddyconfig/httpcaddyfile/serveroptions.go
@@ -162,7 +162,7 @@ func unmarshalCaddyfileServerOptions(d *caddyfile.Dispenser) (any, error) {
 					}
 					serverOpts.Protocols = append(serverOpts.Protocols, proto)
 				}
-				if d.NextBlock(0) {
+				if nesting := d.Nesting(); d.NextBlock(nesting) {
 					return nil, d.ArgErr()
 				}
 


Test patch:
diff --git a/admin_test.go b/admin_test.go
index d53988b3475..04aa8867fc3 100644
--- a/admin_test.go
+++ b/admin_test.go
@@ -161,7 +161,7 @@ func (fooModule) Stop() error  { return nil }
 func TestETags(t *testing.T) {
 	RegisterModule(fooModule{})
 
-	if err := Load([]byte(`{"apps": {"foo": {"strField": "abc", "intField": 0}}}`), true); err != nil {
+	if err := Load([]byte(`{"admin": {"listen": "localhost:2999"}, "apps": {"foo": {"strField": "abc", "intField": 0}}}`), true); err != nil {
 		t.Fatalf("loading: %s", err)
 	}
 
diff --git a/caddytest/integration/caddyfile_adapt/global_server_options_single.txt b/caddytest/integration/caddyfile_adapt/global_server_options_single.txt
index cfe6bfdfe34..5fb67392954 100644
--- a/caddytest/integration/caddyfile_adapt/global_server_options_single.txt
+++ b/caddytest/integration/caddyfile_adapt/global_server_options_single.txt
@@ -12,8 +12,8 @@
 		}
 		max_header_size 100MB
 		log_credentials
-		strict_sni_host
 		protocols h1 h2 h2c h3
+		strict_sni_host
 	}
 }