Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
adding charset=utf-8 to Content-Type header for html documents (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Mendenhall authored and markbates committed Sep 20, 2018
1 parent 93538a2 commit 131515d
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func productionErrorResponseFor(status int) []byte {

func defaultErrorHandler(status int, origErr error, c Context) error {
env := c.Value("env")
ct := defaults.String(httpx.ContentType(c.Request()), "text/html")
ct := defaults.String(httpx.ContentType(c.Request()), "text/html; charset=utf-8")
c.Response().Header().Set("content-type", ct)

c.Logger().Error(origErr)
Expand Down
2 changes: 1 addition & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_defaultErrorHandler_SetsContentType(t *testing.T) {
res := w.HTML("/").Get()
r.Equal(401, res.Code)
ct := res.Header().Get("content-type")
r.Equal("text/html", ct)
r.Equal("text/html; charset=utf-8", ct)
}

func Test_PanicHandler(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion render/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (e *Engine) HTML(names ...string) Renderer {
}
hr := &templateRenderer{
Engine: e,
contentType: "text/html",
contentType: "text/html; charset=utf-8",
names: names,
}
return hr
Expand Down
6 changes: 3 additions & 3 deletions render/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_HTML(t *testing.T) {
}).HTML

re := j(filepath.Base(tmpFile.Name()))
r.Equal("text/html", re.ContentType())
r.Equal("text/html; charset=utf-8", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand All @@ -61,7 +61,7 @@ func Test_HTML(t *testing.T) {
r := require.New(sst)
h := re.HTML(filepath.Base(tmpFile.Name()))

r.Equal("text/html", h.ContentType())
r.Equal("text/html; charset=utf-8", h.ContentType())
bb := &bytes.Buffer{}
err = h.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand All @@ -78,7 +78,7 @@ func Test_HTML(t *testing.T) {
r.NoError(err)
h := re.HTML(filepath.Base(tmpFile.Name()), filepath.Base(nlayout.Name()))

r.Equal("text/html", h.ContentType())
r.Equal("text/html; charset=utf-8", h.ContentType())
bb := &bytes.Buffer{}
err = h.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions render/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_Markdown(t *testing.T) {

for _, j := range table {
re := j(filepath.Base(tmpFile.Name()))
r.Equal("text/html", re.ContentType())
r.Equal("text/html; charset=utf-8", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand All @@ -61,7 +61,7 @@ func Test_Markdown(t *testing.T) {
TemplatesBox: packr.NewBox(tmpDir),
}).HTML(filepath.Base(tmpFile.Name()))

r.Equal("text/html", re.ContentType())
r.Equal("text/html; charset=utf-8", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion render/partials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_Template_Partial_WithoutExtension(t *testing.T) {
err := withHTMLFile("index.html", `<%= partial("foo") %>`, func(e *Engine) {
err := withHTMLFile("_foo.html", "Foo > <%= name %>", func(e *Engine) {

re := e.Template("text/html", "index.html")
re := e.Template("text/html; charset=utf-8", "index.html")
bb := &bytes.Buffer{}
err := re.Render(bb, Data{"name": "Mark"})
r.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func New(opts Options) *Engine {
}

if opts.DefaultContentType == "" {
opts.DefaultContentType = "text/html"
opts.DefaultContentType = "text/html; charset=utf-8"
}

e := &Engine{
Expand Down
6 changes: 3 additions & 3 deletions render/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func Test_AssetPath(t *testing.T) {
_, err = tmpFile.Write([]byte("<%= assetPath(\"" + original + "\") %>"))
r.NoError(err)

result := re("text/html", filepath.Base(tmpFile.Name()))
result := re("text/html; charset=utf-8", filepath.Base(tmpFile.Name()))

bb := &bytes.Buffer{}
err = result.Render(bb, render.Data{})
Expand Down Expand Up @@ -123,7 +123,7 @@ func Test_AssetPathNoManifest(t *testing.T) {
_, err = tmpFile.Write([]byte("<%= assetPath(\"" + original + "\") %>"))
r.NoError(err)

result := re("text/html", filepath.Base(tmpFile.Name()))
result := re("text/html; charset=utf-8", filepath.Base(tmpFile.Name()))

bb := &bytes.Buffer{}
err = result.Render(bb, render.Data{})
Expand Down Expand Up @@ -166,7 +166,7 @@ func Test_AssetPathManifestCorrupt(t *testing.T) {
_, err = tmpFile.Write([]byte("<%= assetPath(\"" + original + "\") %>"))
r.NoError(err)

result := re("text/html", filepath.Base(tmpFile.Name()))
result := re("text/html; charset=utf-8", filepath.Base(tmpFile.Name()))

bb := &bytes.Buffer{}
err = result.Render(bb, render.Data{})
Expand Down

0 comments on commit 131515d

Please sign in to comment.