summaryrefslogtreecommitdiffhomepage
path: root/caddyhttp
diff options
context:
space:
mode:
authorPeer Beckmann <[email protected]>2016-09-28 20:23:44 +0200
committerMatt Holt <[email protected]>2016-09-28 12:23:44 -0600
commitbb7787d2ee99cd401c345fb47d75ce0449ea23ee (patch)
tree1cea0e7ac960c62ddcb85c32257a2af9d787541c /caddyhttp
parent8620581f95df9fa7ae987ea6a36123ecdb0a7321 (diff)
downloadcaddy-bb7787d2ee99cd401c345fb47d75ce0449ea23ee.tar.gz
caddy-bb7787d2ee99cd401c345fb47d75ce0449ea23ee.zip
Remove the eager check in the browse middleware (#1144)
* Remove the eager check in the browse middleware, whether the root directory exists. Caddy will start and throw a 404-error until the directory will be created. * Add the complimentary test. - Tests the startup of the browse middleware if the site root is inexistent and browse is pointing to the site root. * Some minor stylistic tweaks.
Diffstat (limited to 'caddyhttp')
-rw-r--r--caddyhttp/browse/setup.go9
-rw-r--r--caddyhttp/browse/setup_test.go16
2 files changed, 14 insertions, 11 deletions
diff --git a/caddyhttp/browse/setup.go b/caddyhttp/browse/setup.go
index b860d847c..290915421 100644
--- a/caddyhttp/browse/setup.go
+++ b/caddyhttp/browse/setup.go
@@ -62,15 +62,6 @@ func browseParse(c *caddy.Controller) ([]Config, error) {
bc.PathScope = "/"
}
bc.Root = http.Dir(cfg.Root)
- theRoot, err := bc.Root.Open("/") // catch a missing path early
- if err != nil {
- return configs, err
- }
- defer theRoot.Close()
- _, err = theRoot.Readdir(-1)
- if err != nil {
- return configs, err
- }
// Second argument would be the template file to use
var tplText string
diff --git a/caddyhttp/browse/setup_test.go b/caddyhttp/browse/setup_test.go
index 0531cc224..534eb16f6 100644
--- a/caddyhttp/browse/setup_test.go
+++ b/caddyhttp/browse/setup_test.go
@@ -18,7 +18,7 @@ func TestSetup(t *testing.T) {
if err != nil {
t.Fatalf("BeforeTest: Failed to find an existing directory for testing! Error was: %v", err)
}
- nonExistantDirPath := filepath.Join(tempDirPath, strconv.Itoa(int(time.Now().UnixNano())))
+ nonExistentDirPath := filepath.Join(tempDirPath, strconv.Itoa(int(time.Now().UnixNano())))
tempTemplate, err := ioutil.TempFile(".", "tempTemplate")
if err != nil {
@@ -43,7 +43,7 @@ func TestSetup(t *testing.T) {
{"browse . " + tempTemplatePath, []string{"."}, false},
// test case #3 tests detection of non-existent template
- {"browse . " + nonExistantDirPath, nil, true},
+ {"browse . " + nonExistentDirPath, nil, true},
// test case #4 tests detection of duplicate pathscopes
{"browse " + tempDirPath + "\n browse " + tempDirPath, nil, true},
@@ -66,4 +66,16 @@ func TestSetup(t *testing.T) {
}
}
}
+
+ // test case #6 tests startup with missing root directory in combination with default browse settings
+ controller := caddy.NewTestController("http", "browse")
+ cfg := httpserver.GetConfig(controller)
+
+ // Make sure non-existent root path doesn't return error
+ cfg.Root = nonExistentDirPath
+ err = setup(controller)
+
+ if err != nil {
+ t.Errorf("Test for non-existent browse path received an error, but shouldn't have: %v", err)
+ }
}