summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/server.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-05 13:36:42 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-05 13:36:42 -0600
commit80b54f3b9d5e207316fb9e8f83dd1e90659b25d7 (patch)
treecdbd23fbcb898970ed5ff20b004866db6ccd8cb1 /modules/caddyhttp/server.go
parent0830fbad0347ead1dbea60e664556b263e44653f (diff)
Add original URI to request context; implement into fastcgi env
Diffstat (limited to 'modules/caddyhttp/server.go')
-rw-r--r--modules/caddyhttp/server.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index 248e5f2..04935e6 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -20,6 +20,7 @@ import (
"log"
"net"
"net/http"
+ "net/url"
"strconv"
"strings"
@@ -58,6 +59,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl)
ctx = context.WithValue(ctx, ServerCtxKey, s)
ctx = context.WithValue(ctx, VarCtxKey, make(map[string]interface{}))
+ ctx = context.WithValue(ctx, OriginalURLCtxKey, cloneURL(r.URL))
r = r.WithContext(ctx)
// once the pointer to the request won't change
@@ -228,6 +230,18 @@ type HTTPErrorConfig struct {
Routes RouteList `json:"routes,omitempty"`
}
+// cloneURL makes a copy of r.URL and returns a
+// new value that doesn't reference the original.
+func cloneURL(u *url.URL) url.URL {
+ urlCopy := *u
+ if u.User != nil {
+ userInfo := new(url.Userinfo)
+ *userInfo = *u.User
+ urlCopy.User = userInfo
+ }
+ return urlCopy
+}
+
// Context keys for HTTP request context values.
const (
// For referencing the server instance
@@ -235,4 +249,7 @@ const (
// For the request's variable table
VarCtxKey caddy.CtxKey = "vars"
+
+ // For the unmodified URL that originally came in with a request
+ OriginalURLCtxKey caddy.CtxKey = "original_url"
)