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-04-05 19:04:21 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-04-05 19:04:21 +0300
commitb0ac2a7d3f7c48702120de4910cde34b7aee7bdd (patch)
treea8aaad3f80b5dcf51f2d3e8905d5da1172784c07
parent5c830cca6dee4ad6f0025dda14fa345bb677e38c (diff)
Fix: Content-Type of predefined 404 pagev0.2.2
-rw-r--r--404.go12
-rw-r--r--CHANGELOG3
-rw-r--r--VERSION2
-rw-r--r--app.go2
-rw-r--r--domain.go4
-rw-r--r--domain_test.go21
6 files changed, 32 insertions, 12 deletions
diff --git a/404.go b/404.go
index e5f8ec91..3634ddf0 100644
--- a/404.go
+++ b/404.go
@@ -1,5 +1,10 @@
package main
+import (
+ "net/http"
+ "fmt"
+)
+
const predefined404 = `
<!DOCTYPE html>
<html>
@@ -56,3 +61,10 @@ const predefined404 = `
</body>
</html>
`
+
+func serve404(w http.ResponseWriter) {
+ w.Header().Set("Content-Type", "text/plain; charset=utf-8")
+ w.Header().Set("X-Content-Type-Options", "nosniff")
+ w.WriteHeader(http.StatusNotFound)
+ fmt.Fprintln(w, predefined404)
+}
diff --git a/CHANGELOG b/CHANGELOG
index 8e6ad7f6..ed0a6e52 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v 0.2.2
+- Fix predefined 404 page content-type
+
v 0.2.1
- Serve nice GitLab branded 404 page
- Present user's error page for 404: put the 404.html in root of your pages
diff --git a/VERSION b/VERSION
index 0c62199f..ee1372d3 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.2.1
+0.2.2
diff --git a/app.go b/app.go
index 4c690845..aa0438ff 100644
--- a/app.go
+++ b/app.go
@@ -56,7 +56,7 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo
domain := a.domain(r.Host)
if domain == nil {
- http.NotFound(&w, r)
+ serve404(&w)
return
}
diff --git a/domain.go b/domain.go
index 186eb6b6..e274e274 100644
--- a/domain.go
+++ b/domain.go
@@ -169,7 +169,7 @@ func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) {
}
// Serve generic not found
- http.Error(w, predefined404, http.StatusNotFound)
+ serve404(w)
}
func (d *domain) serveFromConfig(w http.ResponseWriter, r *http.Request) {
@@ -184,7 +184,7 @@ func (d *domain) serveFromConfig(w http.ResponseWriter, r *http.Request) {
}
// Serve generic not found
- http.Error(w, predefined404, http.StatusNotFound)
+ serve404(w)
}
func (d *domain) ensureCertificate() (*tls.Certificate, error) {
diff --git a/domain_test.go b/domain_test.go
index d1dca06e..56e032a4 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -5,6 +5,9 @@ import (
"net/http"
"net/url"
"testing"
+ "net/http/httptest"
+ "github.com/stretchr/testify/require"
+ "mime"
)
func TestGroupServeHTTP(t *testing.T) {
@@ -48,14 +51,16 @@ func TestDomainServeHTTP(t *testing.T) {
assert.HTTPError(t, testDomain.ServeHTTP, "GET", "/not-existing-file", nil)
}
-func testHTTP404(t *testing.T, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool {
- if !assert.HTTPError(t, handler, mode, url, values) {
- return false
- }
- if !assert.HTTPBodyContains(t, handler, mode, url, values, str) {
- return false
- }
- return true
+func testHTTP404(t *testing.T, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) {
+ w := httptest.NewRecorder()
+ req, err := http.NewRequest(mode, url+"?"+values.Encode(), nil)
+ require.NoError(t, err)
+ handler(w, req)
+
+ contentType, _, _ := mime.ParseMediaType(w.Header().Get("Content-Type"))
+ assert.Equal(t, http.StatusNotFound, w.Code, "HTTP status")
+ assert.Equal(t, "text/html", contentType, "Content-Type")
+ assert.Contains(t, w.Body.String(), str)
}
func TestGroup404ServeHTTP(t *testing.T) {