summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Hansen <[email protected]>2015-04-28 13:15:14 -0600
committerThomas Hansen <[email protected]>2015-04-28 13:15:14 -0600
commit17fa5a93348328be4d4f2f91df0d5b299354251d (patch)
tree4a2afb6fc13407d0d1b0886a2af5e50a561f3626
parent9b74901b40d0b1f2bafceceaf98174252d8208d4 (diff)
downloadcaddy-17fa5a93348328be4d4f2f91df0d5b299354251d.tar.gz
caddy-17fa5a93348328be4d4f2f91df0d5b299354251d.zip
adding support for fastcgi index files in subdirectories
-rw-r--r--middleware/fastcgi/fastcgi.go33
1 files changed, 20 insertions, 13 deletions
diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go
index 3c9f9eab2..2e88013c6 100644
--- a/middleware/fastcgi/fastcgi.go
+++ b/middleware/fastcgi/fastcgi.go
@@ -60,14 +60,21 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
// we probably want to exclude static assets (CSS, JS, images...)
// but we also want to be flexible for the script we proxy to.
+ path := r.URL.Path
+
// These criteria work well in this order for PHP sites
- if middleware.Path(r.URL.Path).Matches(rule.Path) &&
- (r.URL.Path[len(r.URL.Path)-1] == '/' ||
- strings.HasSuffix(r.URL.Path, rule.Ext) ||
- !h.exists(r.URL.Path)) {
+ if middleware.Path(path).Matches(rule.Path) &&
+ (path[len(path)-1] == '/' ||
+ strings.HasSuffix(path, rule.Ext) ||
+ !h.exists(path)) {
+
+ if path[len(path)-1] == '/' && h.exists(path+rule.IndexFile) {
+ // If index file in specified folder exists, send request to it
+ path += rule.IndexFile
+ }
// Create environment for CGI script
- env, err := h.buildEnv(r, rule)
+ env, err := h.buildEnv(r, rule, path)
if err != nil {
return http.StatusInternalServerError, err
}
@@ -123,11 +130,11 @@ func (h Handler) exists(path string) bool {
return false
}
-func (h Handler) buildEnv(r *http.Request, rule Rule) (map[string]string, error) {
+func (h Handler) buildEnv(r *http.Request, rule Rule, path string) (map[string]string, error) {
var env map[string]string
// Get absolute path of requested resource
- absPath, err := filepath.Abs(h.Root + r.URL.Path)
+ absPath, err := filepath.Abs(h.Root + path)
if err != nil {
return env, err
}
@@ -142,19 +149,19 @@ func (h Handler) buildEnv(r *http.Request, rule Rule) (map[string]string, error)
}
// Split path in preparation for env variables
- splitPos := strings.Index(r.URL.Path, rule.SplitPath)
+ splitPos := strings.Index(path, rule.SplitPath)
var docURI, scriptName, scriptFilename, pathInfo string
if splitPos == -1 {
- // Request doesn't have the extension, so assume index file
+ // Request doesn't have the extension, so assume index file in root
docURI = "/" + rule.IndexFile
scriptName = "/" + rule.IndexFile
scriptFilename = h.Root + "/" + rule.IndexFile
- pathInfo = r.URL.Path
+ pathInfo = path
} else {
// Request has the extension; path was split successfully
- docURI = r.URL.Path[:splitPos+len(rule.SplitPath)]
- pathInfo = r.URL.Path[splitPos+len(rule.SplitPath):]
- scriptName = r.URL.Path
+ docURI = path[:splitPos+len(rule.SplitPath)]
+ pathInfo = path[splitPos+len(rule.SplitPath):]
+ scriptName = path
scriptFilename = absPath
}