httk.serve.http.accept¶
Parse and select against RFC 9110 Accept media ranges.
This module consolidates the RFC 9110 Accept-header parsing shared by the
lightweight JSON applications and the DSP catalogue policy. Parsing is common;
selection deliberately is not, so two separately named selectors are exposed:
one keeps parameterised ranges and matches their parameters, the other discards
any range that carries a parameter.
Classes¶
One valid media range parsed from an HTTP |
Functions¶
|
Split an HTTP field outside quoted strings, rejecting broken quoting. |
|
Decode one token or quoted-string parameter value. |
|
Parse a JSON media type into its major, minor, and parameters. |
|
Parse an |
|
Select the best range that keeps and matches its parameters. |
|
Select the best range, discarding any range carrying a parameter. |
Module Contents¶
- class httk.serve.http.accept.MediaRange[source]¶
One valid media range parsed from an HTTP
Acceptheader.- Parameters:
major – Lowercase major type, or
"*"for a wildcard.minor – Lowercase minor type, or
"*"for a wildcard.parameters – Non-
qparameters as immutable lowercase name-value pairs.quality – The
qweight, defaulting to1.0when absent.
- httk.serve.http.accept.split_http_list(value, delimiter)[source]¶
Split an HTTP field outside quoted strings, rejecting broken quoting.
- httk.serve.http.accept.http_parameter_value(value)[source]¶
Decode one token or quoted-string parameter value.
- httk.serve.http.accept.parse_media_type(value)[source]¶
Parse a JSON media type into its major, minor, and parameters.
- httk.serve.http.accept.parse_accept(header)[source]¶
Parse an
Acceptheader into its valid media ranges.- Parameters:
header (str) – The raw
Acceptheader value.- Returns:
The valid parsed media ranges, or
()when the header cannot be split.- Return type:
tuple[MediaRange, Ellipsis]
- httk.serve.http.accept.best_quality_matching_parameters(ranges, major, minor, parameters)[source]¶
Select the best range that keeps and matches its parameters.
A parameterised range is kept only when every one of its parameters is present and equal in
parameters. The specificity tiebreak favours a more specific major/minor match and then a range carrying more parameters.- Parameters:
ranges (tuple[MediaRange, Ellipsis]) – The parsed media ranges to select among.
major (str) – The response major type to match.
minor (str) – The response minor type to match.
parameters (collections.abc.Mapping[str, str]) – The response media-type parameters to match against.
- Returns:
The winning range’s quality, or
Nonewhen nothing matches.- Return type:
float | None
- httk.serve.http.accept.best_quality_ignoring_parameterised(ranges, major, minor)[source]¶
Select the best range, discarding any range carrying a parameter.
Any range that carries a parameter is discarded outright. The specificity tiebreak favours a more specific major/minor match, with a constant second component.
- Parameters:
ranges (tuple[MediaRange, Ellipsis]) – The parsed media ranges to select among.
major (str) – The response major type to match.
minor (str) – The response minor type to match.
- Returns:
The winning range’s quality, or
Nonewhen nothing matches.- Return type:
float | None