Skip to content
Myr

issue_1721: fix render writeHeaders to make it the same as http.Header.Set (#1722)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by songjiayang · committed by 田欧 · parent 184661c · Browse files · 2 files+4 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+4 added−2 removed

  • other:+4 added−2 removed

2 files+4 added−2 removed

modified:render/reader.go+2 added-2 removed
34 unmodified lines
35// writeHeaders writes custom Header.36func (r Reader) writeHeaders(w http.ResponseWriter, headers map[string]string) {37 header := w.Header()38 for k, v := range headers {39 if val := header[k]; len(val) == 0 {40 header[k] = []string{v}39 if header.Get(k) == "" {40 header.Set(k, v)41 }42 }43}
modified:render/render_test.go+2 added
468 unmodified lines
469470 body := "#!PNG some raw data"471 headers := make(map[string]string)472 headers["Content-Disposition"] = `attachment; filename="filename.png"`473 headers["x-request-id"] = "requestId"474475 err := (Reader{476 ContentLength: int64(len(body)),477 ContentType: "image/png",
5 unmodified lines
483 assert.Equal(t, body, w.Body.String())484 assert.Equal(t, "image/png", w.Header().Get("Content-Type"))485 assert.Equal(t, strconv.Itoa(len(body)), w.Header().Get("Content-Length"))486 assert.Equal(t, headers["Content-Disposition"], w.Header().Get("Content-Disposition"))487 assert.Equal(t, headers["x-request-id"], w.Header().Get("x-request-id"))488}