summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/replacer.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-10-14 12:09:43 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-10-14 12:09:43 -0600
commitacf7dea68fe6ace110221faa26c2503a1ea432ce (patch)
tree7be6cea0e3e62a2e42a8b141517164e8dc4f3b9c /modules/caddyhttp/replacer.go
parentbc738991b6234bf334855e1396919e79ef9791b8 (diff)
caddyhttp: host labels placeholders endianness from right->left
https://caddy.community/t/labeln-placeholder-endian-issue/5366 (I thought we had this before but it must have gotten lost somewhere)
Diffstat (limited to 'modules/caddyhttp/replacer.go')
-rw-r--r--modules/caddyhttp/replacer.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index 205e4ed..db329be 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -146,14 +146,18 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon
if err != nil {
return "", false
}
- hostLabels := strings.Split(req.Host, ".")
+ reqHost, _, err := net.SplitHostPort(req.Host)
+ if err != nil {
+ reqHost = req.Host // OK; assume there was no port
+ }
+ hostLabels := strings.Split(reqHost, ".")
if idx < 0 {
return "", false
}
- if idx >= len(hostLabels) {
+ if idx > len(hostLabels) {
return "", true
}
- return hostLabels[idx], true
+ return hostLabels[len(hostLabels)-idx-1], true
}
// path parts