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
30b19190
Commit
30b19190
authored
Sep 17, 2015
by
Henrique Dias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ignoreIndexes option to browse
parent
840bc505
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
middleware/browse/browse.go
middleware/browse/browse.go
+11
-8
No files found.
middleware/browse/browse.go
View file @
30b19190
...
...
@@ -26,6 +26,7 @@ type Browse struct {
Next
middleware
.
Handler
Root
string
Configs
[]
Config
IgnoreIndexes
bool
}
// Config is a configuration for browsing in a particular path.
...
...
@@ -142,18 +143,20 @@ var IndexPages = []string{
"default.txt"
,
}
func
directoryListing
(
files
[]
os
.
FileInfo
,
r
*
http
.
Request
,
canGoUp
bool
,
root
string
)
(
Listing
,
error
)
{
func
directoryListing
(
files
[]
os
.
FileInfo
,
r
*
http
.
Request
,
canGoUp
bool
,
root
string
,
ignoreIndexes
bool
)
(
Listing
,
error
)
{
var
fileinfos
[]
FileInfo
var
urlPath
=
r
.
URL
.
Path
for
_
,
f
:=
range
files
{
name
:=
f
.
Name
()
// Directory is not browsable if it contains index file
if
!
ignoreIndexes
{
for
_
,
indexName
:=
range
IndexPages
{
if
name
==
indexName
{
return
Listing
{},
errors
.
New
(
"Directory contains index file, not browsable!"
)
}
}
}
if
f
.
IsDir
()
{
name
+=
"/"
...
...
@@ -234,7 +237,7 @@ func (b Browse) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
}
}
// Assemble listing of directory contents
listing
,
err
:=
directoryListing
(
files
,
r
,
canGoUp
,
b
.
Root
)
listing
,
err
:=
directoryListing
(
files
,
r
,
canGoUp
,
b
.
Root
,
b
.
IgnoreIndexes
)
if
err
!=
nil
{
// directory isn't browsable
continue
}
...
...
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