From 02b50e2ffbbfec7e4c815fe7572fbd73e65f3b7f Mon Sep 17 00:00:00 2001 From: chestnutprog Date: Tue, 4 Oct 2016 23:21:33 +0800 Subject: [PATCH] fix writing of multiple headers with the same name --- h2quic/response_writer.go | 4 +++- h2quic/response_writer_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/h2quic/response_writer.go b/h2quic/response_writer.go index 6120ca35b..7e9b7f960 100644 --- a/h2quic/response_writer.go +++ b/h2quic/response_writer.go @@ -49,7 +49,9 @@ func (w *responseWriter) WriteHeader(status int) { enc.WriteField(hpack.HeaderField{Name: ":status", Value: strconv.Itoa(status)}) for k, v := range w.header { - enc.WriteField(hpack.HeaderField{Name: strings.ToLower(k), Value: v[0]}) + for index := range v { + enc.WriteField(hpack.HeaderField{Name: strings.ToLower(k), Value: v[index]}) + } } utils.Infof("Responding with %d", status) diff --git a/h2quic/response_writer_test.go b/h2quic/response_writer_test.go index 3d5d56e6e..d67709457 100644 --- a/h2quic/response_writer_test.go +++ b/h2quic/response_writer_test.go @@ -48,6 +48,16 @@ var _ = Describe("Response Writer", func() { })) }) + It("writes multiple headers with the same name", func() { + w.Header().Add("set-cookie", "test1=1; Max-Age=7200; path=/") + w.Header().Add("set-cookie", "test2=2; Max-Age=7200; path=/") + w.WriteHeader(http.StatusTeapot) + Expect(headerStream.Bytes()).To(Equal([]byte{0x00, 0x00, 0x33, 0x01, 0x04, 0x00, 0x00, 0x00, 0x05, + 0x48, 0x03, 0x34, 0x31, 0x38, 0x77, 0x95, 0x49, 0x50, 0x90, 0xc0, 0x1f, 0xb5, 0x34, 0x0f, 0xca, 0xd0, 0xcc, + 0x58, 0x1d, 0x10, 0x01, 0xf6, 0xa5, 0x63, 0x4c, 0xf0, 0x31, 0x77, 0x95, 0x49, 0x50, 0x91, 0x40, 0x2f, 0xb5, + 0x34, 0x0f, 0xca, 0xd0, 0xcc, 0x58, 0x1d, 0x10, 0x01, 0xf6, 0xa5, 0x63, 0x4c, 0xf0, 0x31})) + }) + It("writes data", func() { n, err := w.Write([]byte("foobar")) Expect(n).To(Equal(6))