diff options
author | Matt Holt <mholt@users.noreply.github.com> | 2019-09-09 21:46:21 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-09 21:46:21 -0600 |
commit | 44b7ce98505ab8a34f6c632e661dd2cfae475a17 (patch) | |
tree | 4cd125e485047419fd19098007280b013906a0bc /modules/caddyhttp/server.go | |
parent | 9169cd43d49236c69d5c9b7c556cb0ac0c9ce497 (diff) | |
parent | b4f4fcd437c2f9816f9511217bde703679808679 (diff) |
Merge pull request #2737 from caddyserver/fastcgi (reverse proxy!)
v2: Refactor reverse proxy and add FastCGI support
Diffstat (limited to 'modules/caddyhttp/server.go')
-rw-r--r-- | modules/caddyhttp/server.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go index 5b651fc..42f7a5a 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 @@ -168,7 +170,7 @@ func (s *Server) enforcementHandler(w http.ResponseWriter, r *http.Request, next // listeners in s that use a port which is not otherPort. func (s *Server) listenersUseAnyPortOtherThan(otherPort int) bool { for _, lnAddr := range s.Listen { - _, addrs, err := caddy.ParseListenAddr(lnAddr) + _, addrs, err := caddy.ParseNetworkAddress(lnAddr) if err == nil { for _, a := range addrs { _, port, err := net.SplitHostPort(a) @@ -254,6 +256,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 @@ -261,4 +275,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" ) |