mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
7527c01705
* http: path matcher: exact match by default; substring matches (#2959) This is a breaking change. * caddyfile: Change "matcher" directive to "@matcher" syntax (#2959) * cmd: Assume caddyfile adapter for config files named Caddyfile * Sub-sort handlers by path matcher length (#2959) Caddyfile-generated subroutes have handlers, which are sorted first by directive order (this is unchanged), but within directives we now sort by specificity of path matcher in descending order (longest path first, assuming that longest path is most specific). This only applies if there is only one matcher set, and the path matcher in that set has only one path in it. Path matchers with two or more paths are not sorted like this; and routes with more than one matcher set are not sorted like this either, since specificity is difficult or impossible to infer correctly. This is a special case, but definitely a very common one, as a lot of routing decisions are based on paths. * caddyfile: New 'route' directive for appearance-order handling (#2959) * caddyfile: Make rewrite directives mutually exclusive (#2959) This applies only to rewrites in the top-level subroute created by the HTTP caddyfile.
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
// Copyright 2015 Matthew Holt and The Caddy Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package httpcaddyfile
|
|
|
|
import (
|
|
"testing"
|
|
|
|
caddyfile "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
|
|
for i, tc := range []struct {
|
|
input string
|
|
expectWarn bool
|
|
expectError bool
|
|
}{
|
|
{
|
|
input: `http://localhost
|
|
@debug {
|
|
query showdebug=1
|
|
}
|
|
`,
|
|
expectWarn: false,
|
|
expectError: false,
|
|
},
|
|
{
|
|
input: `http://localhost
|
|
@debug {
|
|
query bad format
|
|
}
|
|
`,
|
|
expectWarn: false,
|
|
expectError: true,
|
|
},
|
|
} {
|
|
|
|
adapter := caddyfile.Adapter{
|
|
ServerType: ServerType{},
|
|
}
|
|
|
|
_, warnings, err := adapter.Adapt([]byte(tc.input), nil)
|
|
|
|
if len(warnings) > 0 != tc.expectWarn {
|
|
t.Errorf("Test %d warning expectation failed Expected: %v, got %v", i, tc.expectWarn, warnings)
|
|
continue
|
|
}
|
|
|
|
if err != nil != tc.expectError {
|
|
t.Errorf("Test %d error expectation failed Expected: %v, got %s", i, tc.expectError, err)
|
|
continue
|
|
}
|
|
}
|
|
}
|