Documentation
¶
Overview ¶
Package negotiation provides stable core HTTP content negotiation helpers.
Use New when a service wants one middleware to enforce both Accept and Content-Type policy, or RequireAccept and RequireContentType for focused checks. ParseAccept, Negotiate, and ContentTypeAllowed expose the same matching behavior for handlers and tests.
The package writes Problem Details 406 and 415 responses and does not inspect request bodies, route metadata, or OpenAPI documents. Keep media-type policy explicit in application routing or route contracts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentTypeAllowed ¶
ContentTypeAllowed reports whether a Content-Type is allowed.
func RequireAccept ¶
RequireAccept returns middleware that enforces response media negotiation.
Types ¶
type Accept ¶
type Accept struct {
MediaType string
Type string
Subtype string
Params map[string]string
Q float64
Order int
}
Accept is one parsed Accept header item.
func ParseAccept ¶
ParseAccept parses an Accept header and sorts values by client preference.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware enforces Accept and Content-Type policies.
func New ¶
func New(config Config) (*Middleware, error)
New constructs content negotiation middleware.
func (*Middleware) Handler ¶
func (m *Middleware) Handler(next http.Handler) http.Handler
Handler wraps next with Accept and Content-Type checks.
func (*Middleware) Middleware ¶
func (m *Middleware) Middleware() func(http.Handler) http.Handler
Middleware returns the standard middleware adapter.