Standard library / net/http
http.Header.WriteSubset()
Writes headers in wire format, excluding the exact keys marked true in the exclusion map. Expected stdout: '"X-A: one\\r\\n"\n'.
Formal Syntax & Structure
go syntaxgo
func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| w | io.Writer | Destination writer. |
| exclude | map[string]bool | Input value of the declared type; see the usage example. |
Return Value
error
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "net/http")
func main() { h := http.Header{"X-A": {"one"}, "X-B": {"two"}} var b bytes.Buffer check(h.WriteSubset(&b, map[string]bool{"X-B": true})) fmt.Printf("%q\n", b.String())}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}