From 4e94b85ec20f5d8c74076fed0c7cb42f9261ab87 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sat, 23 May 2015 03:39:23 +0100 Subject: [PATCH] FastCGI: support for unix sockets. --- middleware/fastcgi/fastcgi.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index 6d7fd1f8..2eae0668 100644 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -58,7 +58,14 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) } // Connect to FastCGI gateway - fcgi, err := Dial("tcp", rule.Address) + var fcgi *FCGIClient + + // check if unix socket or tcp + if strings.HasPrefix(rule.Address, "/") { + fcgi, err = Dial("unix", rule.Address) + } else { + fcgi, err = Dial("tcp", rule.Address) + } if err != nil { return http.StatusBadGateway, err } @@ -83,7 +90,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) default: return http.StatusMethodNotAllowed, nil } - defer resp.Body.Close() + + if resp.Body != nil { + defer resp.Body.Close() + } if err != nil && err != io.EOF { return http.StatusBadGateway, err