/* textproto.MIMEHeader is a named map type, and canonicalization holds. `type MIMEHeader map[string][][]byte` carries Add, Set, Get, Values and Del as methods. A value receiver over a named map is a reference receiver, so the mutations reach the caller. The interesting part of this type is that every operation CANONICALIZES the key (CanonicalMIMEHeaderKey), which is what makes header lookup case-insensitive - so the fixture pins that, not just storage: a key written as `x-lower` is found as `X-LOWER`, and a value written as `Content-Type` is found as `content-type`. It also pins Get returning the FIRST of several values and Del removing them all. net/http.Header's five delegating methods were inlined to direct map operations in the same round, so this type's methods now have exactly one caller shape: the free functions below. */ package main import ( "net/textproto" ) func main() { // Termination: a batch program must still be stoppable, so the entry // handles the channel the runtime closes on SIGINT/SIGTERM. select { case <-shutdown: return default: } h := textproto.MIMEHeader{} h.Set("Content-Type", "text/plain") h.Add("X-Multi", "one") h.Add("X-Multi", "two") h.Set("x-lower", "yes") if h.Get("content-type") != "text/plain" { panic("get canonicalized key") } if h.Get("X-LOWER") != "yes" { panic("get lower-case written key") } vs := h.Values("x-multi") if len(vs) != 2 || string(vs[1]) != "two" { panic("values keeps every value in order") } h.Del("X-Multi") if h.Get("x-multi") != "" { panic("del removes every value") } println("mimeheader ok") }