Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
17fa5a93
Commit
17fa5a93
authored
Apr 28, 2015
by
Thomas Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding support for fastcgi index files in subdirectories
parent
9b74901b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
middleware/fastcgi/fastcgi.go
middleware/fastcgi/fastcgi.go
+20
-13
No files found.
middleware/fastcgi/fastcgi.go
View file @
17fa5a93
...
...
@@ -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
.
P
ath
)
absPath
,
err
:=
filepath
.
Abs
(
h
.
Root
+
p
ath
)
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
.
P
ath
,
rule
.
SplitPath
)
splitPos
:=
strings
.
Index
(
p
ath
,
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
.
P
ath
pathInfo
=
p
ath
}
else
{
// Request has the extension; path was split successfully
docURI
=
r
.
URL
.
P
ath
[
:
splitPos
+
len
(
rule
.
SplitPath
)]
pathInfo
=
r
.
URL
.
P
ath
[
splitPos
+
len
(
rule
.
SplitPath
)
:
]
scriptName
=
r
.
URL
.
P
ath
docURI
=
p
ath
[
:
splitPos
+
len
(
rule
.
SplitPath
)]
pathInfo
=
p
ath
[
splitPos
+
len
(
rule
.
SplitPath
)
:
]
scriptName
=
p
ath
scriptFilename
=
absPath
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment