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
10ab0378
Commit
10ab0378
authored
Sep 19, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved fileServer and browse.IndexPages into middleware package
parent
540a651f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
20 deletions
+33
-20
config/setup/controller_test.go
config/setup/controller_test.go
+0
-0
dist/CHANGES.txt
dist/CHANGES.txt
+2
-0
middleware/browse/browse.go
middleware/browse/browse.go
+2
-11
middleware/fileserver.go
middleware/fileserver.go
+28
-8
server/virtualhost.go
server/virtualhost.go
+1
-1
No files found.
config/setup/controllertest.go
→
config/setup/controller
_
test.go
View file @
10ab0378
File moved
dist/CHANGES.txt
View file @
10ab0378
...
...
@@ -4,7 +4,9 @@ CHANGES
- basicauth: Support for legacy htpasswd files
- browse: JSON response with file listing given Accept header
- core: Caddyfile as command line argument
- errors, log: Roll log files after certain size or age
- templates: Added .StripExt and .StripHTML methods
- Internal improvements and minor bug fixes
0.7.5 (August 5, 2015)
...
...
middleware/browse/browse.go
View file @
10ab0378
...
...
@@ -56,7 +56,7 @@ type Listing struct {
// And which order
Order
string
//
User defined costum variabl
es
//
Optional custom variables for use in browse templat
es
User
interface
{}
middleware
.
Context
...
...
@@ -138,15 +138,6 @@ func (fi FileInfo) HumanModTime(format string) string {
return
fi
.
ModTime
.
Format
(
format
)
}
var
IndexPages
=
[]
string
{
"index.html"
,
"index.htm"
,
"index.txt"
,
"default.html"
,
"default.htm"
,
"default.txt"
,
}
func
directoryListing
(
files
[]
os
.
FileInfo
,
r
*
http
.
Request
,
canGoUp
bool
,
root
string
,
ignoreIndexes
bool
,
vars
interface
{})
(
Listing
,
error
)
{
var
fileinfos
[]
FileInfo
var
urlPath
=
r
.
URL
.
Path
...
...
@@ -155,7 +146,7 @@ func directoryListing(files []os.FileInfo, r *http.Request, canGoUp bool, root s
// Directory is not browsable if it contains index file
if
!
ignoreIndexes
{
for
_
,
indexName
:=
range
IndexPages
{
for
_
,
indexName
:=
range
middleware
.
IndexPages
{
if
name
==
indexName
{
return
Listing
{},
errors
.
New
(
"Directory contains index file, not browsable!"
)
}
...
...
server
/fileserver.go
→
middleware
/fileserver.go
View file @
10ab0378
package
server
package
middleware
import
(
"net/http"
"os"
"path"
"strings"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/browse"
)
// This file contains a standard way for Caddy middleware
// to load files from the file system given a request
// URI and path to site root. Other middleware that load
// files should use these facilities.
// FileServer implements a production-ready file server
// and is the 'default' handler for all requests to Caddy.
// It simply loads and serves the URI requested. If Caddy is
// run without any extra configuration/directives, this is the
// only middleware handler that runs. It is not in its own
// folder like most other middleware handlers because it does
// not require a directive. It is a special case.
//
// FileServer is adapted from the one in net/http by
// the Go authors. Significant modifications have been made.
//
//
// License:
// Original license:
//
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
func
FileServer
(
root
http
.
FileSystem
,
hide
[]
string
)
middleware
.
Handler
{
func
FileServer
(
root
http
.
FileSystem
,
hide
[]
string
)
Handler
{
return
&
fileHandler
{
root
:
root
,
hide
:
hide
}
}
...
...
@@ -82,7 +91,7 @@ func (fh *fileHandler) serveFile(w http.ResponseWriter, r *http.Request, name st
// use contents of an index file, if present, for directory
if
d
.
IsDir
()
{
for
_
,
indexPage
:=
range
browse
.
IndexPages
{
for
_
,
indexPage
:=
range
IndexPages
{
index
:=
strings
.
TrimSuffix
(
name
,
"/"
)
+
"/"
+
indexPage
ff
,
err
:=
fh
.
root
.
Open
(
index
)
if
err
==
nil
{
...
...
@@ -134,3 +143,14 @@ func redirect(w http.ResponseWriter, r *http.Request, newPath string) {
}
http
.
Redirect
(
w
,
r
,
newPath
,
http
.
StatusMovedPermanently
)
}
// IndexPages is a list of pages that may be understood as
// the "index" files to directories.
var
IndexPages
=
[]
string
{
"index.html"
,
"index.htm"
,
"index.txt"
,
"default.html"
,
"default.htm"
,
"default.txt"
,
}
server/virtualhost.go
View file @
10ab0378
...
...
@@ -20,7 +20,7 @@ type virtualHost struct {
// on its config. This method should be called last before
// ListenAndServe begins.
func
(
vh
*
virtualHost
)
buildStack
()
error
{
vh
.
fileServer
=
FileServer
(
http
.
Dir
(
vh
.
config
.
Root
),
[]
string
{
vh
.
config
.
ConfigFile
})
vh
.
fileServer
=
middleware
.
FileServer
(
http
.
Dir
(
vh
.
config
.
Root
),
[]
string
{
vh
.
config
.
ConfigFile
})
// TODO: We only compile middleware for the "/" scope.
// Partial support for multiple location contexts already
...
...
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