Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-05 17:45:41 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-05 17:45:41 +0300
commit16e576be89c0654ff6ffa78d8f3e27d8eba033e0 (patch)
tree126efbdea10885238918dcf1d2178455764bbe66
parentcdc785b6b65e8cb811c9ea67616381ad95285745 (diff)
parenta8942247992d272ae29074d362a2c6b7de6bf96b (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.go2
-rw-r--r--domain.go2
-rw-r--r--domain_test.go10
-rw-r--r--helpers.go5
4 files changed, 17 insertions, 2 deletions
diff --git a/404.go b/404.go
index 5bcced47..0ac0be54 100644
--- a/404.go
+++ b/404.go
@@ -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)
diff --git a/domain.go b/domain.go
index e274e274..46f57ed0 100644
--- a/domain.go
+++ b/domain.go
@@ -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",
diff --git a/helpers.go b/helpers.go
index cd989b97..edcf583d 100644
--- a/helpers.go
+++ b/helpers.go
@@ -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, "/")
+}