Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowContentType ¶
func AllowContentType(contentTypes []string, opts ...Option) middleware.MiddlewareFunc
AllowContentType creates middleware that validates if the request's Content-Type header is included in the specified list.
If the Content-Type header does not exist or has a media type not in the list, it returns a response with status code 415 (Unsupported Media Type) and "Unsupported Media Type" body by default. The response body can be customized with the WithResponse option.
If the contentTypes list is empty, all Content-Types will be rejected. Content-Type comparison is done only on the media type part, parameters (e.g., charset=utf-8) are ignored. Comparison is case-insensitive.
Examples: AllowContentType([]string{"application/json"}) allows "application/json" and "application/json; charset=utf-8". AllowContentType([]string{"application/json", "application/xml"}) allows both JSON and XML.