Documentation
¶
Overview ¶
Package internal provides non-exported helpers for the problem module.
It currently contains HTTP Accept negotiation logic used to select response media types for problem rendering.
This package is internal to the module and not part of the public API contract.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accept ¶
type Accept struct {
// contains filtered or unexported fields
}
Accept represents a parsed HTTP Accept header for content negotiation. It retains valid media requirements and weights in client order without modifying requests. Order compares those requirements with full supported content types, including parameters; it performs no response I/O.
func ParseAccept ¶
ParseAccept parses the Accept header values from request. Invalid ranges are ignored; missing or wholly invalid headers let Order retain the server's supported order. Parsing does not modify the request.
Example:
request := httptest.NewRequest(http.MethodGet, "/", nil)
request.Header.Set("Accept", "application/json")
preferred := internal.ParseAccept(request).Order([]string{"text/plain", "application/json"})
_ = preferred[0] // "application/json"
func (Accept) Order ¶
Order returns acceptable supported content types in client preference order. Supported values may include parameters; results preserve their original strings. Missing or wholly invalid Accept ranges keep server order. Matching parameters increase specificity; charset values compare case-insensitively.
Example:
request := httptest.NewRequest(http.MethodGet, "/", nil)
request.Header.Set("Accept", "text/plain;charset=UTF-8")
preferred := internal.ParseAccept(request).Order([]string{"text/plain; charset=utf-8"})
_ = preferred[0]