Skip to content

Commit

Permalink
httpcaddyfile: Sort directives with any matcher before those with none
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Aug 16, 2020
1 parent b661bec commit ef802ea
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions caddyconfig/httpcaddyfile/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ func sortRoutes(routes []ConfigValue) {
jPathLen = len(jPM[0])
}

// if both directives have no path matcher, use whichever one
// has any kind of matcher defined first.
if iPathLen == 0 && jPathLen == 0 {
return len(iRoute.MatcherSetsRaw) > len(jRoute.MatcherSetsRaw)
}

// sort the "root" directive in reverse because we want the
// most-specific path last such that the root variable
// overrides a less-specific one.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
:80

file_server

@untrusted not remote_ip 10.1.1.0/24
file_server @untrusted
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":80"
],
"routes": [
{
"match": [
{
"not": [
{
"remote_ip": {
"ranges": [
"10.1.1.0/24"
]
}
}
]
}
],
"handle": [
{
"handler": "file_server",
"hide": [
"Caddyfile"
]
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"Caddyfile"
]
}
]
}
]
}
}
}
}
}

0 comments on commit ef802ea

Please sign in to comment.