Standard library / net/http

http.CanonicalHeaderKey()

Canonicalize a valid header field name; invalid names are returned unchanged. Expected stdout: 'Content-Type\n'.

Formal Syntax & Structure

go syntaxgo
func CanonicalHeaderKey(s string) string

Parameters & Attributes

NameTypeDescription
sstringText to escape, unescape or canonicalize.

Return Value

string

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() { fmt.Println(http.CanonicalHeaderKey("content-type")) }
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