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
9672850d
Commit
9672850d
authored
Mar 24, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixes and improvements for browse middleware
parent
00e43197
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
middleware/browse/browse.go
middleware/browse/browse.go
+33
-0
No files found.
middleware/browse/browse.go
View file @
9672850d
...
@@ -55,6 +55,13 @@ type FileInfo struct {
...
@@ -55,6 +55,13 @@ type FileInfo struct {
Mode
os
.
FileMode
Mode
os
.
FileMode
}
}
var
IndexPages
=
[]
string
{
"index.html"
,
"index.htm"
,
"default.html"
,
"default.htm"
,
}
// New creates a new instance of browse middleware.
// New creates a new instance of browse middleware.
func
New
(
c
middleware
.
Controller
)
(
middleware
.
Middleware
,
error
)
{
func
New
(
c
middleware
.
Controller
)
(
middleware
.
Middleware
,
error
)
{
configs
,
err
:=
parse
(
c
)
configs
,
err
:=
parse
(
c
)
...
@@ -89,11 +96,20 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -89,11 +96,20 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
return
}
}
// See if there's a browse configuration to match the path
for
_
,
bc
:=
range
b
.
Configs
{
for
_
,
bc
:=
range
b
.
Configs
{
if
!
middleware
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
bc
.
PathScope
)
{
if
!
middleware
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
bc
.
PathScope
)
{
continue
continue
}
}
// Browsing navigation gets messed up if browsing a directory
// that doesn't end in "/" (which it should, anyway)
if
r
.
URL
.
Path
[
len
(
r
.
URL
.
Path
)
-
1
]
!=
'/'
{
http
.
Redirect
(
w
,
r
,
r
.
URL
.
Path
+
"/"
,
http
.
StatusTemporaryRedirect
)
return
}
// Load directory contents
file
,
err
:=
os
.
Open
(
b
.
Root
+
r
.
URL
.
Path
)
file
,
err
:=
os
.
Open
(
b
.
Root
+
r
.
URL
.
Path
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
// TODO
panic
(
err
)
// TODO
...
@@ -109,8 +125,21 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -109,8 +125,21 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Assemble listing of directory contents
// Assemble listing of directory contents
var
fileinfos
[]
FileInfo
var
fileinfos
[]
FileInfo
var
abort
bool
// we bail early if we find an index file
for
_
,
f
:=
range
files
{
for
_
,
f
:=
range
files
{
name
:=
f
.
Name
()
name
:=
f
.
Name
()
// Directory is not browseable if it contains index file
for
_
,
indexName
:=
range
IndexPages
{
if
name
==
indexName
{
abort
=
true
break
}
}
if
abort
{
break
}
if
f
.
IsDir
()
{
if
f
.
IsDir
()
{
name
+=
"/"
name
+=
"/"
}
}
...
@@ -125,6 +154,10 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -125,6 +154,10 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Mode
:
f
.
Mode
(),
Mode
:
f
.
Mode
(),
})
})
}
}
if
abort
{
// this dir has an index file, so not browsable
continue
}
// Determine if user can browse up another folder
// Determine if user can browse up another folder
var
canGoUp
bool
var
canGoUp
bool
...
...
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