Skip to content

Commit

Permalink
httpcaddyfile: Flip root directive sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Aug 16, 2020
1 parent e385be9 commit b661bec
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions caddyconfig/httpcaddyfile/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ func sortRoutes(routes []ConfigValue) {
if len(jPM) > 0 {
jPathLen = len(jPM[0])
}

// sort the "root" directive in reverse because we want the
// most-specific path last such that the root variable
// overrides a less-specific one.
if iDir == "root" {
return iPathLen < jPathLen
}

// sort any other directives with the most-specific path first
return iPathLen > jPathLen
})
}
Expand Down
57 changes: 57 additions & 0 deletions caddytest/integration/caddyfile_adapt/sort_root_with_path_last.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
:80

root * /foo
root /z* /bar

file_server
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":80"
],
"routes": [
{
"group": "group1",
"handle": [
{
"handler": "vars",
"root": "/foo"
}
]
},
{
"group": "group1",
"match": [
{
"path": [
"/z*"
]
}
],
"handle": [
{
"handler": "vars",
"root": "/bar"
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"Caddyfile"
]
}
]
}
]
}
}
}
}
}

0 comments on commit b661bec

Please sign in to comment.