//:wasmtest skip // Native-only by COST, measured, not by failure: linking net/http for -target wasm // makes this fixture the most expensive one in the tree - its native and wasm builds // together take ~35 minutes, and tests/wasm/validate.sh wipes the per-compiler package // cache at the start of every run on purpose ("each run measures a cold compile"), // so the cost is paid on EVERY phase-5 run. It is not hidden: this fixture DOES // validate in the browser - gojs stubs and all - when run directly, which is how the // host capability was proved in round 108: // // MOXIE=./moxie bash tests/wasm/validate.sh tests/regressions/should_compile/http_header_api.mx // // Header behaviour natively is covered every run (phase 0), and net/http COMPILING for // wasm is covered every run (phase 1c). /* http.Header is a named map type, and the whole API works through its methods. `type Header map[string][][]byte` carries Add, Set, Get, Values, Del, Clone, Write and WriteSubset as methods. A value receiver over a named map is a reference receiver, so the mutations reach the caller. The NAME survives: a Header is written Header{...}, converted with Header(...) and read with h[key], and the Request/Response fields are unchanged. This is a MAIN-package fixture deliberately: an unresolved call inside a library package's body is dropped SILENTLY (round 99), so only a main package proves the free functions exist. It pins canonicalization, first-value Get, all-values, Del, Clone independence, and both writers. NATIVE-ONLY, and the reason is the TARGET, not this fixture: linking net/http for `-target wasm` pulls its `js && wasm` files, so the module imports the `gojs` bridge, and the standalone-wasm validator host does not provide that module - the browser run dies at instantiation with WebAssembly.instantiate(): Import #18 "gojs": module is not an object or function That is true of ANY fixture importing net/http; net/http's wasm COMPILATION is covered by phase 1c (`wasm:net/http PASS`), and this fixture covers the API behaviour natively. Recorded in the work log. */ package main import ( "bytes" "net/http" ) 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 := http.Header{} h.Set("Content-Type", "text/plain") h.Add("X-Multi", "one") h.Add("X-Multi", "two") if h.Get("content-type") != "text/plain" { panic("get canonicalized key") } vs := h.Values("x-multi") if len(vs) != 2 || string(vs[1]) != "two" { panic("values keeps every value in order") } c := h.Clone() c.Del("X-Multi") if c.Get("x-multi") != "" { panic("del removes every value") } if h.Get("x-multi") == "" { panic("clone must be independent of the original") } var buf bytes.Buffer if err := h.Write(&buf); err != nil { panic("write") } if buf.Len() == 0 { panic("write produced nothing") } var buf2 bytes.Buffer if err := h.WriteSubset(&buf2, map[string]bool{"X-Multi": true}); err != nil { panic("writesubset") } println("header ok") }