A client may send the same header name more than once, and HTTP says those repeats combine into one comma-separated value. Today you fold duplicates instead of letting a later line silently overwrite an earlier one.
Combine repeated header fields of the same name into a single comma-separated value.
Header fields can legitimately repeat. The spec says a recipient may combine multiple fields of the same name into one value by joining them with commas, in the order they arrived — and for most headers that is exactly equivalent to having sent one comma-separated value.
The trap is the naive map[key] = value, which throws away every value but the
last. Instead, check whether the key already exists and append with ", " when
it does. Order matters, so always append the newcomer to the end.
key := strings.ToLower(name)if existing, ok := h[key]; ok {h[key] = existing + ", " + value // append, do not overwrite} else {h[key] = value}