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
ee615371
Commit
ee615371
authored
Aug 06, 2016
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Export staticfiles.Redirect for convenience in preserving query string
parent
4c6082df
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
caddyhttp/browse/browse.go
caddyhttp/browse/browse.go
+1
-1
caddyhttp/staticfiles/fileserver.go
caddyhttp/staticfiles/fileserver.go
+7
-7
No files found.
caddyhttp/browse/browse.go
View file @
ee615371
...
...
@@ -288,7 +288,7 @@ inScope:
// Browsing navigation gets messed up if browsing a directory
// that doesn't end in "/" (which it should, anyway)
if
!
strings
.
HasSuffix
(
r
.
URL
.
Path
,
"/"
)
{
http
.
Redirect
(
w
,
r
,
r
.
URL
.
Path
+
"/"
,
http
.
StatusTemporaryRedirect
)
staticfiles
.
Redirect
(
w
,
r
,
r
.
URL
.
Path
+
"/"
,
http
.
StatusTemporaryRedirect
)
return
0
,
nil
}
...
...
caddyhttp/staticfiles/fileserver.go
View file @
ee615371
...
...
@@ -81,13 +81,13 @@ func (fs FileServer) serveFile(w http.ResponseWriter, r *http.Request, name stri
if
d
.
IsDir
()
{
// Ensure / at end of directory url
if
!
strings
.
HasSuffix
(
url
,
"/"
)
{
redirect
(
w
,
r
,
path
.
Base
(
url
)
+
"/"
)
Redirect
(
w
,
r
,
path
.
Base
(
url
)
+
"/"
,
http
.
StatusMovedPermanently
)
return
http
.
StatusMovedPermanently
,
nil
}
}
else
{
// Ensure no / at end of file url
if
strings
.
HasSuffix
(
url
,
"/"
)
{
redirect
(
w
,
r
,
"../"
+
path
.
Base
(
url
)
)
Redirect
(
w
,
r
,
"../"
+
path
.
Base
(
url
),
http
.
StatusMovedPermanently
)
return
http
.
StatusMovedPermanently
,
nil
}
}
...
...
@@ -149,14 +149,14 @@ func (fs FileServer) isHidden(d os.FileInfo) bool {
return
false
}
//
redirect is taken from http.localRedirect of the std lib. It
//
sends an HTTP permanent redirect to the client but will
//
preserve the query string for the new path
.
func
redirect
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
newPath
string
)
{
//
Redirect sends an HTTP redirect to the client but will preserve
//
the query string for the new path. Based on http.localRedirect
//
from the Go standard library
.
func
Redirect
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
newPath
string
,
statusCode
int
)
{
if
q
:=
r
.
URL
.
RawQuery
;
q
!=
""
{
newPath
+=
"?"
+
q
}
http
.
Redirect
(
w
,
r
,
newPath
,
http
.
StatusMovedPermanently
)
http
.
Redirect
(
w
,
r
,
newPath
,
statusCode
)
}
// IndexPages is a list of pages that may be understood as
...
...
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