Commit 22707edc authored by Matthew Holt's avatar Matthew Holt

Refactored fastcgi middleware to return errors

parent 7578298b
...@@ -6,7 +6,6 @@ package fastcgi ...@@ -6,7 +6,6 @@ package fastcgi
import ( import (
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -27,8 +26,8 @@ func New(c middleware.Controller) (middleware.Middleware, error) { ...@@ -27,8 +26,8 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
rules = append(rules, rule) rules = append(rules, rule)
} }
return func(next http.HandlerFunc) http.HandlerFunc { return func(next middleware.HandlerFunc) middleware.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) (int, error) {
servedFcgi := false servedFcgi := false
for _, rule := range rules { for _, rule := range rules {
...@@ -38,15 +37,13 @@ func New(c middleware.Controller) (middleware.Middleware, error) { ...@@ -38,15 +37,13 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
// Get absolute file paths // Get absolute file paths
absPath, err := filepath.Abs(root + r.URL.Path) absPath, err := filepath.Abs(root + r.URL.Path)
if err != nil { if err != nil {
// TODO! return http.StatusInternalServerError, err
log.Fatal(err)
} }
// Get absolute file paths // Get absolute file path to website root
absRootPath, err := filepath.Abs(root) absRootPath, err := filepath.Abs(root)
if err != nil { if err != nil {
// TODO! return http.StatusInternalServerError, err
log.Fatal(err)
} }
// Separate remote IP and port // Separate remote IP and port
...@@ -73,17 +70,17 @@ func New(c middleware.Controller) (middleware.Middleware, error) { ...@@ -73,17 +70,17 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
fcgi, err := Dial("tcp", rule.address) fcgi, err := Dial("tcp", rule.address)
if err != nil { if err != nil {
// TODO! return http.StatusBadGateway, err
} }
resp, err := fcgi.Get(env) resp, err := fcgi.Get(env)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
// TODO! return http.StatusBadGateway, err
} }
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
// TODO! return http.StatusBadGateway, err
} }
for key, vals := range resp.Header { for key, vals := range resp.Header {
...@@ -100,8 +97,10 @@ func New(c middleware.Controller) (middleware.Middleware, error) { ...@@ -100,8 +97,10 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
} }
if !servedFcgi { if !servedFcgi {
next(w, r) return next(w, r)
} }
return 0, nil
} }
}, nil }, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment