Documentation
¶
Overview ¶
Package implement HTTP Content-Type and Accept header parsers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Media type in the Content-Type or Accept header is syntactically invalid. ErrInvalidMediaType = errors.New("invalid media type") // Range of media types in the Content-Type or Accept header is syntactically invalid. ErrInvalidMediaRange = errors.New("invalid media range") // Media type parameter in the Content-Type or Accept header is syntactically invalid. ErrInvalidParameter = errors.New("invalid parameter") // Media type extension parameter in the Content-Type or Accept header is syntactically invalid. ErrInvalidExtensionParameter = errors.New("invalid extension parameter") // Accept header contains only media types that are not in the acceptable media type list. ErrNoAcceptableTypeFound = errors.New("no acceptable type found") // Acceptbale media type list is empty. ErrNoAvailableTypeGiven = errors.New("no available type given") // Media type weight in the Accept header is syntactically invalid. ErrInvalidWeight = errors.New("invalid wieght") )
Functions ¶
func GetAcceptableMediaType ¶
func GetAcceptableMediaType(request *http.Request, availableMediaTypes []MediaType) (MediaType, Parameters, error)
Choses a media type from available media types according to the Accept. Returns the most suitable media type or an error if no type can be selected.
func GetAcceptableMediaTypeFromHeader ¶ added in v1.0.1
func GetAcceptableMediaTypeFromHeader(headerValue string, availableMediaTypes []MediaType) (MediaType, Parameters, error)
Choses a media type from available media types according to the specified Accept header value. Returns the most suitable media type or an error if no type can be selected.
Types ¶
type MediaType ¶
type MediaType struct {
Type string
Subtype string
Parameters Parameters
}
A struct for media type which holds type, subtype and parameters.
func GetMediaType ¶
Gets the content of Content-Type header, parses it, and returns the parsed MediaType. If the request does not contain the Content-Type header, an empty MediaType is returned.
func NewMediaType ¶
Parses the string and returns an instance of MediaType struct.
func ParseMediaType ¶ added in v1.0.1
Parses the given string as a MIME media type (with optional parameters) and returns it as a MediaType. If the string cannot be parsed an appropriate error is returned.