Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpcaddyfile: Support single-line matchers #3263

Merged
merged 3 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion caddyconfig/httpcaddyfile/httptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ func parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.M
// handle more than one segment); otherwise, we'd overwrite other
// instances of the matcher in this set
tokensByMatcherName := make(map[string][]caddyfile.Token)
for nesting := d.Nesting(); d.NextBlock(nesting); {
for nesting := d.Nesting(); d.NextArg() || d.NextBlock(nesting); {
matcherName := d.Val()
tokensByMatcherName[matcherName] = append(tokensByMatcherName[matcherName], d.NextSegment()...)
}
Expand Down
7 changes: 7 additions & 0 deletions caddyconfig/httpcaddyfile/httptype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func TestMatcherSyntax(t *testing.T) {
expectWarn: false,
expectError: false,
},
{
input: `http://localhost
@debug not path /somepath*
`,
expectWarn: false,
expectError: false,
},
} {

adapter := caddyfile.Adapter{
Expand Down
80 changes: 80 additions & 0 deletions caddytest/integration/caddyfile_adapt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,83 @@ func TestHttpOnlyOnNonStandardPort(t *testing.T) {
}
}`)
}

func TestMatcherSyntax(t *testing.T) {
caddytest.AssertAdapt(t, `
:80 {
@matcher {
method GET
}
respond @matcher "get"

@matcher2 method POST
respond @matcher2 "post"

@matcher3 not method PUT
respond @matcher3 "not put"
}
`, "caddyfile", `{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":80"
],
"routes": [
{
"match": [
{
"method": [
"GET"
]
}
],
"handle": [
{
"body": "get",
"handler": "static_response"
}
]
},
{
"match": [
{
"method": [
"POST"
]
}
],
"handle": [
{
"body": "post",
"handler": "static_response"
}
]
},
{
"match": [
{
"not": [
{
"method": [
"PUT"
]
}
]
}
],
"handle": [
{
"body": "not put",
"handler": "static_response"
}
]
}
]
}
}
}
}
}`)
}