Standard library / net/textproto
textproto.CanonicalMIMEHeaderKey()
Normalize valid ASCII header keys. Invalid keys are returned unchanged, so canonicalization is not validation. Expected stdout: 'Content-Type\nbad key\n'.
Formal Syntax & Structure
go syntaxgo
func CanonicalMIMEHeaderKey(s string) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Input string to process. |
Return Value
string
Canonical key or unchanged invalid key.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/textproto")
func main() { fmt.Println(textproto.CanonicalMIMEHeaderKey("content-type")) fmt.Println(textproto.CanonicalMIMEHeaderKey("bad key"))}
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) }}