aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/replacer.go
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2019-10-10 15:38:30 -0600
committerMatthew Holt <[email protected]>2019-10-10 15:38:30 -0600
commit9c0bf311f93218e8f899cd3c6102868be18a4d1c (patch)
treede74b8a08c09b26aad05f065e2ba61f857ae7284 /modules/caddyhttp/replacer.go
parent5300949e0def70411fde307afad4c15b6cc22dfd (diff)
downloadcaddy-9c0bf311f93218e8f899cd3c6102868be18a4d1c.tar.gz
caddy-9c0bf311f93218e8f899cd3c6102868be18a4d1c.zip
Miscellaneous cleanups / comments
Diffstat (limited to 'modules/caddyhttp/replacer.go')
-rw-r--r--modules/caddyhttp/replacer.go45
1 files changed, 38 insertions, 7 deletions
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index d4baa3f0c..205e4ed5f 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -19,6 +19,7 @@ import (
"net"
"net/http"
"net/textproto"
+ "net/url"
"path"
"strconv"
"strings"
@@ -59,6 +60,15 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon
}
switch key {
+ case "http.request.method":
+ return req.Method, true
+ case "http.request.scheme":
+ if req.TLS != nil {
+ return "https", true
+ }
+ return "http", true
+ case "http.request.proto":
+ return req.Proto, true
case "http.request.host":
host, _, err := net.SplitHostPort(req.Host)
if err != nil {
@@ -81,13 +91,8 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon
case "http.request.remote.port":
_, port, _ := net.SplitHostPort(req.RemoteAddr)
return port, true
- case "http.request.method":
- return req.Method, true
- case "http.request.scheme":
- if req.TLS != nil {
- return "https", true
- }
- return "http", true
+
+ // current URI, including any internal rewrites
case "http.request.uri":
return req.URL.RequestURI(), true
case "http.request.uri.path":
@@ -106,6 +111,32 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon
qs = "?" + qs
}
return qs, true
+
+ // original URI, before any internal changes
+ case "http.request.orig_uri":
+ u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL)
+ return u.RequestURI(), true
+ case "http.request.orig_uri.path":
+ u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL)
+ return u.Path, true
+ case "http.request.orig_uri.path.file":
+ u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL)
+ _, file := path.Split(u.Path)
+ return file, true
+ case "http.request.orig_uri.path.dir":
+ u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL)
+ dir, _ := path.Split(u.Path)
+ return dir, true
+ case "http.request.orig_uri.query":
+ u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL)
+ return u.RawQuery, true
+ case "http.request.orig_uri.query_string":
+ u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL)
+ qs := u.Query().Encode()
+ if qs != "" {
+ qs = "?" + qs
+ }
+ return qs, true
}
// hostname labels