From 14b64fef43381ee0e9719b3f5e4f14a115c19b0b Mon Sep 17 00:00:00 2001 From: Slawomir Jasinski Date: Thu, 11 Jun 2015 09:59:30 +1000 Subject: [PATCH 1/4] fix #127 fixes issue with Status header coming from php-fpm 5.5 different then regular "HTTP/1.1 200 OK". If server returns Status code - "200" will be handled properly instead "throwing runtime error: index out of range" --- middleware/fastcgi/fcgiclient.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/middleware/fastcgi/fcgiclient.go b/middleware/fastcgi/fcgiclient.go index 44b649e6..b2d6ee8e 100644 --- a/middleware/fastcgi/fcgiclient.go +++ b/middleware/fastcgi/fcgiclient.go @@ -375,12 +375,21 @@ func (c *FCGIClient) Request(p map[string]string, req io.Reader) (resp *http.Res resp.Header = http.Header(mimeHeader) if resp.Header.Get("Status") != "" { - statusParts := strings.SplitN(resp.Header.Get("Status"), " ", 2) - resp.StatusCode, err = strconv.Atoi(statusParts[0]) + + // check if Status is long enought to split + if strings.Count(resp.Header.Get("Status"), " ") > 0 { + statusParts := strings.SplitN(resp.Header.Get("Status"), " ", 2) + resp.StatusCode, err = strconv.Atoi(statusParts[0]) + resp.Status = statusParts[1] + resp.Status = statusParts[1] + } else { + resp.StatusCode, err = strconv.Atoi(resp.Header.Get("Status")) + } + if err != nil { return } - resp.Status = statusParts[1] + } else { resp.StatusCode = http.StatusOK } From 29404e34d963130b2c5ae4028328a2326b55e041 Mon Sep 17 00:00:00 2001 From: slav123 Date: Thu, 11 Jun 2015 13:17:56 +1000 Subject: [PATCH 2/4] code cleanup --- middleware/fastcgi/fcgiclient.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/middleware/fastcgi/fcgiclient.go b/middleware/fastcgi/fcgiclient.go index b2d6ee8e..8e6b780a 100644 --- a/middleware/fastcgi/fcgiclient.go +++ b/middleware/fastcgi/fcgiclient.go @@ -375,21 +375,15 @@ func (c *FCGIClient) Request(p map[string]string, req io.Reader) (resp *http.Res resp.Header = http.Header(mimeHeader) if resp.Header.Get("Status") != "" { - - // check if Status is long enought to split - if strings.Count(resp.Header.Get("Status"), " ") > 0 { - statusParts := strings.SplitN(resp.Header.Get("Status"), " ", 2) - resp.StatusCode, err = strconv.Atoi(statusParts[0]) - resp.Status = statusParts[1] - resp.Status = statusParts[1] - } else { - resp.StatusCode, err = strconv.Atoi(resp.Header.Get("Status")) - } - + statusParts := strings.SplitN(resp.Header.Get("Status"), " ", 2) + resp.StatusCode, err = strconv.Atoi(statusParts[0]) if err != nil { return } - + if (len(statusParts) > 0) { + resp.Status = statusParts[1] + } + } else { resp.StatusCode = http.StatusOK } @@ -521,4 +515,4 @@ func (c *FCGIClient) PostFile(p map[string]string, data url.Values, file map[str } // Checks whether chunked is part of the encodings stack -func chunked(te []string) bool { return len(te) > 0 && te[0] == "chunked" } +func chunked(te []string) bool { return len(te) > 0 && te[0] == "chunked" } \ No newline at end of file From db2368cd0b3d4d1b5d9250b365479e497dac595c Mon Sep 17 00:00:00 2001 From: Slawomir Jasinski Date: Fri, 12 Jun 2015 11:33:55 +1000 Subject: [PATCH 3/4] Removed parentheses #127 --- middleware/fastcgi/fcgiclient.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/middleware/fastcgi/fcgiclient.go b/middleware/fastcgi/fcgiclient.go index 8e6b780a..70ddfbe2 100644 --- a/middleware/fastcgi/fcgiclient.go +++ b/middleware/fastcgi/fcgiclient.go @@ -380,7 +380,7 @@ func (c *FCGIClient) Request(p map[string]string, req io.Reader) (resp *http.Res if err != nil { return } - if (len(statusParts) > 0) { + if len(statusParts) > 0 { resp.Status = statusParts[1] } @@ -515,4 +515,4 @@ func (c *FCGIClient) PostFile(p map[string]string, data url.Values, file map[str } // Checks whether chunked is part of the encodings stack -func chunked(te []string) bool { return len(te) > 0 && te[0] == "chunked" } \ No newline at end of file +func chunked(te []string) bool { return len(te) > 0 && te[0] == "chunked" } From f11e1360680a60fcec3deaa4e5f1f49c355abfcf Mon Sep 17 00:00:00 2001 From: Slawomir Jasinski Date: Thu, 18 Jun 2015 09:12:35 +1000 Subject: [PATCH 4/4] Update fcgiclient.go --- middleware/fastcgi/fcgiclient.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/fastcgi/fcgiclient.go b/middleware/fastcgi/fcgiclient.go index 70ddfbe2..b657a3b3 100644 --- a/middleware/fastcgi/fcgiclient.go +++ b/middleware/fastcgi/fcgiclient.go @@ -380,7 +380,7 @@ func (c *FCGIClient) Request(p map[string]string, req io.Reader) (resp *http.Res if err != nil { return } - if len(statusParts) > 0 { + if len(statusParts) > 1 { resp.Status = statusParts[1] }