diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-05 17:45:41 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-05 17:45:41 +0300 |
commit | 16e576be89c0654ff6ffa78d8f3e27d8eba033e0 (patch) | |
tree | 126efbdea10885238918dcf1d2178455764bbe66 | |
parent | cdc785b6b65e8cb811c9ea67616381ad95285745 (diff) | |
parent | a8942247992d272ae29074d362a2c6b7de6bf96b (diff) |
Merge branch 'fix-404-content-type'
* fix-404-content-type:
Fix predefined 404 Content-Type
Add helper for checking if path ends with Slash
-rw-r--r-- | 404.go | 2 | ||||
-rw-r--r-- | domain.go | 2 | ||||
-rw-r--r-- | domain_test.go | 10 | ||||
-rw-r--r-- | helpers.go | 5 |
4 files changed, 17 insertions, 2 deletions
@@ -63,7 +63,7 @@ const predefined404 = ` ` func serve404(w http.ResponseWriter) { - w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("X-Content-Type-Options", "nosniff") w.WriteHeader(http.StatusNotFound) fmt.Fprintln(w, predefined404) @@ -112,7 +112,7 @@ func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string) switch { // If the URL doesn't end with /, send location to client - case fi.IsDir() && !strings.HasSuffix(r.URL.Path, "/"): + case fi.IsDir() && !endsWithSlash(r.URL.Path): newURL := *r.URL newURL.Path += "/" http.Redirect(w, r, newURL.String(), 302) diff --git a/domain_test.go b/domain_test.go index f10009c3..9032aeee 100644 --- a/domain_test.go +++ b/domain_test.go @@ -95,6 +95,16 @@ func TestDomain404ServeHTTP(t *testing.T) { testHTTP404(t, testDomain.ServeHTTP, "GET", "http://group.404.test.io/", nil, "Custom 404 group page") } +func TestPredefined404ServeHTTP(t *testing.T) { + setUpTests() + + testDomain := &domain{ + Group: "group", + } + + testHTTP404(t, testDomain.ServeHTTP, "GET", "http://group.test.io/not-existing-file", nil, "The page you're looking for could not be found") +} + func TestGroupCertificate(t *testing.T) { testGroup := &domain{ Group: "group", @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "net" + "strings" ) func readFile(file string) (result []byte) { @@ -28,3 +29,7 @@ func createSocket(addr string) (l net.Listener, fd uintptr) { fd = f.Fd() return } + +func endsWithSlash(path string) bool { + return strings.HasSuffix(path, "/") +} |