summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/staticfiles/matcher.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-20 21:21:33 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-20 21:21:33 -0600
commita9698728506c580bc38db2e122a5e6ef07f85ce6 (patch)
treea583112f114fc01e09867aa123578861637b04d5 /modules/caddyhttp/staticfiles/matcher.go
parentaaacab1bc3790e3a207ae5d70ca6559cac265bff (diff)
Default error handler; rename StaticFiles -> FileServer
Diffstat (limited to 'modules/caddyhttp/staticfiles/matcher.go')
-rw-r--r--modules/caddyhttp/staticfiles/matcher.go57
1 files changed, 0 insertions, 57 deletions
diff --git a/modules/caddyhttp/staticfiles/matcher.go b/modules/caddyhttp/staticfiles/matcher.go
deleted file mode 100644
index 9ce3f4c..0000000
--- a/modules/caddyhttp/staticfiles/matcher.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package staticfiles
-
-import (
- "net/http"
- "os"
- "path/filepath"
-
- "bitbucket.org/lightcodelabs/caddy2"
- "bitbucket.org/lightcodelabs/caddy2/modules/caddyhttp"
-)
-
-func init() {
- caddy2.RegisterModule(caddy2.Module{
- Name: "http.matchers.file",
- New: func() (interface{}, error) { return new(FileMatcher), nil },
- })
-}
-
-// FileMatcher is a matcher that can match requests
-// based on the local file system.
-// TODO: Not sure how to do this well; we'd need the ability to
-// hide files, etc...
-// TODO: Also consider a feature to match directory that
-// contains a certain filename (use filepath.Glob), useful
-// if wanting to map directory-URI requests where the dir
-// has index.php to PHP backends, for example (although this
-// can effectively be done with rehandling already)
-type FileMatcher struct {
- Root string `json:"root"`
- Path string `json:"path"`
- Flags []string `json:"flags"`
-}
-
-// Match matches the request r against m.
-func (m FileMatcher) Match(r *http.Request) bool {
- // TODO: sanitize path
- fullPath := filepath.Join(m.Root, m.Path)
- var match bool
- if len(m.Flags) > 0 {
- match = true
- fi, err := os.Stat(fullPath)
- for _, f := range m.Flags {
- switch f {
- case "EXIST":
- match = match && os.IsNotExist(err)
- case "DIR":
- match = match && err == nil && fi.IsDir()
- default:
- match = false
- }
- }
- }
- return match
-}
-
-// Interface guard
-var _ caddyhttp.RequestMatcher = (*FileMatcher)(nil)