Documentation
¶
Overview ¶
Package contenttype parses and formats HTTP Content-Type header values, modeled on the npm "content-type" package and RFC 7231.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
func Format(ct ContentType) (string, error)
Format serializes a ContentType back into a header value such as "text/html; charset=utf-8". Parameter values that are not valid tokens are quoted and escaped. Parameters are emitted in sorted name order. It returns an error if the type or any parameter name is invalid.
Types ¶
type ContentType ¶
type ContentType struct {
// Type is the media type, e.g. "text/html". It is always lower-cased.
Type string
// Parameters holds the media type parameters keyed by their lower-cased
// names, e.g. {"charset": "utf-8"}.
Parameters map[string]string
}
ContentType represents a parsed media type and its parameters.
func Parse ¶
func Parse(s string) (ContentType, error)
Parse parses a Content-Type header value such as "text/html; charset=utf-8". The media type and parameter names are lower-cased; quoted parameter values are unquoted and unescaped. It returns an error if the value is malformed.