diff --git a/config/setup/controllertest.go b/config/setup/controller_test.go similarity index 100% rename from config/setup/controllertest.go rename to config/setup/controller_test.go diff --git a/dist/CHANGES.txt b/dist/CHANGES.txt index c01c2ddc..bf4c3c23 100644 --- a/dist/CHANGES.txt +++ b/dist/CHANGES.txt @@ -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) diff --git a/middleware/browse/browse.go b/middleware/browse/browse.go index dbbe25fc..a86c5f02 100644 --- a/middleware/browse/browse.go +++ b/middleware/browse/browse.go @@ -56,7 +56,7 @@ type Listing struct { // And which order Order string - // User defined costum variables + // Optional custom variables for use in browse templates 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!") } diff --git a/server/fileserver.go b/middleware/fileserver.go similarity index 79% rename from server/fileserver.go rename to middleware/fileserver.go index 4d12905b..d8c59b2e 100644 --- a/server/fileserver.go +++ b/middleware/fileserver.go @@ -1,25 +1,34 @@ -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", +} diff --git a/server/virtualhost.go b/server/virtualhost.go index d4fe9c85..b0d15797 100644 --- a/server/virtualhost.go +++ b/server/virtualhost.go @@ -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