From da97ac7c63f1f374357a3a43d8e6a0ef2c61993b Mon Sep 17 00:00:00 2001 From: Harrison Heck Date: Tue, 24 May 2016 15:17:46 -0400 Subject: [PATCH] Strip [] from IPv6 addresses for FastCGI. Fixes #845. --- middleware/fastcgi/fastcgi.go | 4 ++++ middleware/fastcgi/fastcgi_test.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index e481698c..9db71f59 100755 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -183,6 +183,10 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string] ip = r.RemoteAddr } + // Remove [] from IPv6 addresses + ip = strings.Replace(ip, "[", "", 1) + ip = strings.Replace(ip, "]", "", 1) + // Split path in preparation for env variables. // Previous rule.canSplit checks ensure this can never be -1. splitPos := rule.splitPos(fpath) diff --git a/middleware/fastcgi/fastcgi_test.go b/middleware/fastcgi/fastcgi_test.go index 3d93e8ae..e1e39491 100644 --- a/middleware/fastcgi/fastcgi_test.go +++ b/middleware/fastcgi/fastcgi_test.go @@ -137,7 +137,7 @@ func TestBuildEnv(t *testing.T) { fpath := "/fgci_test.php" var envExpected = map[string]string{ - "REMOTE_ADDR": "[2b02:1810:4f2d:9400:70ab:f822:be8a:9093]", + "REMOTE_ADDR": "2b02:1810:4f2d:9400:70ab:f822:be8a:9093", "REMOTE_PORT": "51688", "SERVER_PROTOCOL": "HTTP/1.1", "QUERY_STRING": "test=blabla", @@ -150,7 +150,7 @@ func TestBuildEnv(t *testing.T) { // 2. Test for shorthand notation of IPv6 address r.RemoteAddr = "[::1]:51688" - envExpected["REMOTE_ADDR"] = "[::1]" + envExpected["REMOTE_ADDR"] = "::1" testBuildEnv(&r, rule, fpath, envExpected) // 3. Test for IPv4 address