elazarl / goproxy

An HTTP proxy library for Go
BSD 3-Clause "New" or "Revised" License
5.89k stars 1.07k forks source link

why `copyHeaders` remove dst header key-values first? #259

Open luweimy opened 6 years ago

luweimy commented 6 years ago
func copyHeaders(dst, src http.Header) {
    for k, _ := range dst {
        dst.Del(k)
    }
    for k, vs := range src {
        for _, v := range vs {
            dst.Add(k, v)
        }
    }
}

I write cookie to response in middleware, but goproxy will remove response headers. What should I do?.

elazarl commented 6 years ago

because one header could have multiple values.

Just calling Add would keep the previous value, and add another value to the header.

On Tue, Nov 21, 2017 at 6:23 AM, luwei notifications@github.com wrote:

func copyHeaders(dst, src http.Header) { for k, := range dst { dst.Del(k) } for k, vs := range src { for , v := range vs { dst.Add(k, v) } } }

I write cookie to response in middleware, but goproxy will remove response harders

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/elazarl/goproxy/issues/259, or mute the thread https://github.com/notifications/unsubscribe-auth/AAP4os6f1BtEKRFJcTttR4A-XhLchLsqks5s4lAogaJpZM4QlQ8y .