Skip to content

Commit

Permalink
issue_1721: fix render writeHeaders to make it the same as http.Heade…
Browse files Browse the repository at this point in the history
…r.Set (#1722)
  • Loading branch information
songjiayang authored and thinkerou committed Feb 22, 2019
1 parent 184661c commit 7b1081a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions render/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (r Reader) WriteContentType(w http.ResponseWriter) {
func (r Reader) writeHeaders(w http.ResponseWriter, headers map[string]string) {
header := w.Header()
for k, v := range headers {
if val := header[k]; len(val) == 0 {
header[k] = []string{v}
if header.Get(k) == "" {
header.Set(k, v)
}
}
}
2 changes: 2 additions & 0 deletions render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ func TestRenderReader(t *testing.T) {
body := "#!PNG some raw data"
headers := make(map[string]string)
headers["Content-Disposition"] = `attachment; filename="filename.png"`
headers["x-request-id"] = "requestId"

err := (Reader{
ContentLength: int64(len(body)),
Expand All @@ -483,4 +484,5 @@ func TestRenderReader(t *testing.T) {
assert.Equal(t, "image/png", w.Header().Get("Content-Type"))
assert.Equal(t, strconv.Itoa(len(body)), w.Header().Get("Content-Length"))
assert.Equal(t, headers["Content-Disposition"], w.Header().Get("Content-Disposition"))
assert.Equal(t, headers["x-request-id"], w.Header().Get("x-request-id"))
}

0 comments on commit 7b1081a

Please sign in to comment.