From 845c2702b1fd4d9932a6915a0094a12d06174d33 Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Fri, 14 Oct 2016 21:09:02 +0100 Subject: [PATCH] Prevent Caddy-Rewrite-Original-URI being added as an HTTP ENV variable passed to FastCGI part of fix for #1153 --- caddyhttp/fastcgi/fastcgi.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/caddyhttp/fastcgi/fastcgi.go b/caddyhttp/fastcgi/fastcgi.go index 4cf957d9..3eedf582 100644 --- a/caddyhttp/fastcgi/fastcgi.go +++ b/caddyhttp/fastcgi/fastcgi.go @@ -245,6 +245,7 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string] env["PATH_TRANSLATED"] = filepath.Join(h.AbsRoot, pathInfo) // Info: http://www.oreilly.com/openbook/cgi/ch02_04.html } + // Some web apps rely on knowing HTTPS or not if r.TLS != nil { env["HTTPS"] = "on" @@ -257,13 +258,19 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string] env[envVar[0]] = replacer.Replace(envVar[1]) } - // Add all HTTP headers to env variables + // Add all HTTP headers (except Caddy-Rewrite-Original-URI ) to env variables for field, val := range r.Header { - header := strings.ToUpper(field) - header = headerNameReplacer.Replace(header) - env["HTTP_"+header] = strings.Join(val, ", ") + + if strings.ToUpper(field) != strings.ToUpper(internalRewriteFieldName) { + header := strings.ToUpper(field) + header = headerNameReplacer.Replace(header) + env["HTTP_"+header] = strings.Join(val, ", ") + } + } + + return env, nil }