mirror of https://github.com/gin-gonic/gin.git
issue_1721: fix render writeHeaders to make it the same as http.Header.Set (#1722)
This commit is contained in:
parent
184661cfa2
commit
7b1081a73f
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)),
|
||||
|
@ -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"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue