Standard library / net/http

http.Header.Write()

Write HTTP/1.x header lines to a writer. Expected stdout: '"X-Demo: a\\r\\n"\n'.

Formal Syntax & Structure

go syntaxgo
func (h Header) Write(w io.Writer) error

Parameters & Attributes

NameTypeDescription
wio.WriterDestination writer.

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{}  h.Set("X-Demo", "a")  var b bytes.Buffer  check(h.Write(&b))  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)  }}
Go Reference