API reference¶
Generated from the source and docstrings of http_fields — every name in the package’s
__all__, with its signature, fields, inheritance, and docstring. For a curated, spec-grouped
overview see the header catalog.
Header classes. All classes intended for public use are imported here.
- class http_fields.Accept(*accept_types)¶
Bases:
HeaderAccept header, as defined by RFC 9110.
An Accept header may have an empty value (
Accept:), which is treated as accepting any media type. RFC 9110 no longer includes ext-params (accept-ext) in the grammar.- Parameters:
accept_types (tuple[AcceptType, ...])
- class http_fields.AcceptCharset(*charsets)¶
Bases:
HeaderAccept-Charset header, as defined by RFC 9110.
- class http_fields.AcceptLanguage(*language_ranges)¶
Bases:
HeaderAccept-Language header, as defined by RFC 9110.
- Parameters:
language_ranges (tuple[WeightedLanguageRange, ...])
- class http_fields.AcceptEncoding(*codings)¶
Bases:
HeaderAccept-Encoding header, as defined by RFC 9110.
- Parameters:
codings (tuple[WeightedCoding, ...])
- class http_fields.AcceptRanges(*range_units)¶
Bases:
HeaderAccept-Ranges header, as defined by RFC 9110.
- class http_fields.AccessControlAllowCredentials¶
Bases:
HeaderAccess-Control-Allow-Credentials header (always the literal
true).
- class http_fields.AccessControlAllowHeaders(*items)¶
Bases:
_CorsListAccess-Control-Allow-Headers header.
- Parameters:
items (tuple[CorsFieldName, ...])
- item_type¶
alias of
CorsFieldName
- class http_fields.AccessControlAllowMethods(*items)¶
Bases:
_CorsListAccess-Control-Allow-Methods header.
- Parameters:
items (tuple[CorsMethod, ...])
- item_type¶
alias of
CorsMethod
- class http_fields.AccessControlAllowOrigin(origin)¶
Bases:
HeaderAccess-Control-Allow-Origin header (an origin,
null, or*).- Parameters:
origin (AllowedOrigin)
- class http_fields.AccessControlExposeHeaders(*items)¶
Bases:
_CorsListAccess-Control-Expose-Headers header.
- Parameters:
items (tuple[CorsFieldName, ...])
- item_type¶
alias of
CorsFieldName
- class http_fields.AccessControlMaxAge(max_age)¶
Bases:
HeaderAccess-Control-Max-Age header (delta-seconds).
- Parameters:
max_age (NonNegativeInt)
- class http_fields.AccessControlRequestHeaders(*items)¶
Bases:
_CorsListAccess-Control-Request-Headers header.
- Parameters:
items (tuple[CorsFieldName, ...])
- item_type¶
alias of
CorsFieldName
- class http_fields.AccessControlRequestMethod(method)¶
Bases:
HeaderAccess-Control-Request-Method header (a single method).
- Parameters:
method (RequestedMethod)
- class http_fields.Age(seconds)¶
Bases:
HeaderAge header, as defined by RFC 9111.
- Parameters:
seconds (NonNegativeInt)
- class http_fields.Allow(*methods)¶
Bases:
HeaderAllow header, as defined by RFC 9110.
Allow: GET, POST, OPTIONS
- class http_fields.AltSvc(*values, clear=False)¶
Bases:
HeaderAlt-Svc header, as defined by RFC 7838. The special value
clearis represented byclear=Truewith novalues.
- class http_fields.AltUsed(authority)¶
Bases:
HeaderAlt-Used header, as defined by RFC 7838: the alternative authority actually used.
- Parameters:
authority (AltUsedAuthority)
- class http_fields.AuthenticationInfo(*auth_params)¶
Bases:
AuthParamsHeaderAuthentication-Info header, as defined by RFC 9110.
- class http_fields.Authorization(credentials)¶
Bases:
CredentialsHeaderAuthorization header, as defined by RFC 9110.
- Parameters:
credentials (TokenCredentials | AuthParamCredentials)
- class http_fields.CacheControl(*, immutable=False, public=False, private=False, no_cache=False, no_store=False, no_transform=False, must_revalidate=False, proxy_revalidate=False, max_age=None, max_stale=None, min_fresh=None, only_if_cached=False, s_maxage=None, cache_extension=())¶
Bases:
HeaderCache-Control header, as defined by RFC 9111.
The
no_cacheandprivatedirectives may beTrueor a string of field names. Non-standard directives are carried incache_extension.- Parameters:
- class http_fields.CacheStatus(*members)¶
Bases:
StructuredListHeaderCache-Status header, as defined by RFC 9211. Each
membersitem identifies a cache (its bare value) and carries parameters such ashit,fwd,ttl, anddetail.- Parameters:
members (tuple[Item | InnerList, ...])
- class http_fields.Connection(*directives)¶
Bases:
HeaderConnection header, as defined by RFC 9110.
- class http_fields.ContentDigest(*digests)¶
Bases:
DigestHeaderContent-Digest header, as defined by RFC 9530: a Dictionary of algorithm name to the byte-sequence digest of the message content.
- class http_fields.ContentDisposition(disposition_type, disposition_parms=())¶
Bases:
HeaderContent-Disposition header, as defined by RFC 6266.
- Parameters:
disposition_type (DispositionType)
disposition_parms (tuple[FilenameParm | DispExtParm, ...])
- classmethod build(disposition_type, disposition_parms=None)¶
Build a Content-Disposition from a disposition type and a parameter mapping.
A parameter named
filenameorfilename*(case-insensitive) becomes a FilenameParm; anything else becomes a DispExtParm.
- class http_fields.ContentEncoding(*codings)¶
Bases:
HeaderContent-Encoding header, as defined by RFC 9110.
- class http_fields.ContentLanguage(*languages)¶
Bases:
HeaderContent-Language header, as defined by RFC 9110.
- Parameters:
languages (tuple[LanguageTag, ...])
- class http_fields.ContentLength(length)¶
Bases:
HeaderContent-Length header.
- Parameters:
length (NonNegativeInt)
- class http_fields.ContentLocation(uri)¶
Bases:
UriHeaderContent-Location header, as defined by RFC 9110.
- Parameters:
uri (ContentLocationUri)
- uri_type¶
alias of
ContentLocationUri
- class http_fields.ContentRange(range_unit, *, first_pos=None, last_pos=None, complete_length=None)¶
Bases:
HeaderContent-Range header, as defined by RFC 9110.
- Parameters:
range_unit (RangeUnit)
first_pos (NonNegativeInt | None)
last_pos (NonNegativeInt | None)
complete_length (NonNegativeInt | None)
- class http_fields.ContentType(media_type)¶
Bases:
HeaderContent-Type header, as defined by RFC 9110.
- Parameters:
media_type (MediaType)
- classmethod parse(value)¶
Parse a header value into an instance. Every concrete known header overrides this (CustomHeader carries an arbitrary name and is built via its constructor instead).
- Parameters:
value (str)
- Return type:
Self
- classmethod of(type, subtype, *, charset=None, boundary=None, params=None)¶
Build a Content-Type from its pieces.
charset/boundarytake precedence over any same-named entry inparams.
- class http_fields.Cookie(*pairs)¶
Bases:
HeaderCookie header, as defined by RFC 6265.
- Parameters:
pairs (tuple[CookiePair, ...])
- class http_fields.CustomHeader(name, value)¶
Bases:
HeaderA header with an arbitrary field name, e.g.
X-Request-Id.Both name and value are validated against RFC 9110 (
field-name/field-value).
- class http_fields.Date(date)¶
Bases:
DateHeaderDate header, as defined by RFC 9110.
- Parameters:
date (datetime)
- class http_fields.EntityTag(tag, weak=False)¶
Bases:
objectAn RFC 9110 entity-tag.
__eq__/__hash__are exact (weak flag + opaque tag); usecompare()for the RFC’s weak/strong comparison semantics.
- class http_fields.ETag(entity_tag)¶
Bases:
HeaderETag header, as defined by RFC 9110.
- Parameters:
entity_tag (EntityTag)
- classmethod parse(value)¶
Parse a header value into an instance. Every concrete known header overrides this (CustomHeader carries an arbitrary name and is built via its constructor instead).
- Parameters:
value (str)
- Return type:
Self
- classmethod from_tag(tag, weak=False)¶
Build an ETag from an opaque tag and optional weak flag.
- class http_fields.Expect(*expectations)¶
Bases:
HeaderExpect header, as defined by RFC 9110 (in practice almost always
100-continue).- Parameters:
expectations (tuple[Expectation, ...])
- class http_fields.Expires(date)¶
Bases:
DateHeaderExpires header, as defined by RFC 9111.
- Parameters:
date (datetime)
- class http_fields.Forwarded(*elements)¶
Bases:
HeaderForwarded header, as defined by RFC 7239 (the standardized replacement for the de-facto
X-Forwarded-*headers).- Parameters:
elements (tuple[ForwardedElement, ...])
- class http_fields.From(mailbox)¶
Bases:
HeaderFrom header, as defined by RFC 9110: the mailbox of the user controlling the client.
The mailbox is validated against RFC 9110 (RFC 5322 addr-spec) on construction.
- Parameters:
mailbox (Mailbox)
- class http_fields.Header¶
Bases:
ABCAbstract base for HTTP headers.
Known headers are frozen dataclasses whose fields are the structured components of the header value. Each sets
name(and usuallyrule/visitor) as a ClassVar, implements aparse(value)classmethod, and exposes a derivedvalueproperty. Arbitrary headers (e.g.X-Request-Id) are represented byCustomHeader.- property asgi_value: tuple[bytes, bytes]¶
Return a
(name, value)pair of latin-1 bytes for an ASGI send dict.ASGI encodes header values as ISO-8859-1 (latin-1); using the class encoding keeps this consistent with
__bytes__and accepts obs-text.
- classmethod parse(value)¶
Parse a header value into an instance. Every concrete known header overrides this (CustomHeader carries an arbitrary name and is built via its constructor instead).
- classmethod create(name, value)¶
Return a header for
(name, value): a matching known subclass if one is registered forname, otherwise aCustomHeader.
- class http_fields.Host(hostname, port=None)¶
Bases:
HeaderHost header, as defined by RFC 9110.
Host: www.example.com
- Parameters:
hostname (Hostname)
port (NonNegativeInt | None)
- class http_fields.IfMatch(*entity_tags, wildcard=False)¶
Bases:
EntityTagListHeaderIf-Match header, as defined by RFC 9110.
wildcard(*) matches any current representation.
- class http_fields.IfModifiedSince(date)¶
Bases:
DateHeaderIf-Modified-Since header, as defined by RFC 9110.
- Parameters:
date (datetime)
- class http_fields.IfNoneMatch(*entity_tags, wildcard=False)¶
Bases:
EntityTagListHeaderIf-None-Match header, as defined by RFC 9110.
wildcard(*) matches if any current representation exists.
- class http_fields.IfRange(condition)¶
Bases:
HeaderIf-Range header, as defined by RFC 9110. The condition is an entity-tag or an HTTP-date.
- class http_fields.IfUnmodifiedSince(date)¶
Bases:
DateHeaderIf-Unmodified-Since header, as defined by RFC 9110.
- Parameters:
date (datetime)
- class http_fields.LanguageTag(s, parse=True)¶
Bases:
CaselessMixin,ParsedStrRepresents an RFC 9110 language-tag (BCP 47), matched case-insensitively.
- class http_fields.LastModified(date)¶
Bases:
DateHeaderLast-Modified header, as defined by RFC 9110.
- Parameters:
date (datetime)
- class http_fields.Link(*links)¶
Bases:
HeaderLink header, as defined by RFC 8288 (Web Linking).
- class http_fields.Location(uri)¶
Bases:
UriHeaderLocation header, as defined by RFC 9110.
- Parameters:
uri (LocationUri)
- uri_type¶
alias of
LocationUri
- class http_fields.MaxForwards(forwards)¶
Bases:
HeaderMax-Forwards header, as defined by RFC 9110.
- Parameters:
forwards (NonNegativeInt)
- class http_fields.MediaType(type: str, subtype: str, params: 'list[parameters.Parameter] | tuple[parameters.Parameter, ...] | None' = None)¶
Bases:
object
- class http_fields.Origin(origin)¶
Bases:
HeaderOrigin header, as defined by RFC 6454 / the Fetch standard.
The origin (
scheme://host[:port]ornull) is validated on construction.- Parameters:
origin (OriginValue)
- class http_fields.Prefer(*preferences)¶
Bases:
HeaderPrefer header, as defined by RFC 7240.
- Parameters:
preferences (tuple[Preference, ...])
- class http_fields.PreferenceApplied(*preferences)¶
Bases:
HeaderPreference-Applied header, as defined by RFC 7240.
- Parameters:
preferences (tuple[Preference, ...])
- class http_fields.Priority(urgency=3, incremental=False)¶
Bases:
HeaderPriority header, as defined by RFC 9218: a Structured Fields Dictionary with an
urgency(0-7, default 3) and anincrementalflag (default False). Default values are omitted from the serialized value.
- class http_fields.RangeUnit(s, parse=True)¶
Bases:
CaselessMixin,ParsedStr
- class http_fields.Protocol(name, version=None)¶
Bases:
objectAn RFC 9110 protocol: a name with an optional version, e.g.
HTTP/2.- Parameters:
name (ProtocolName)
version (ProtocolVersion | None)
- class http_fields.ProxyAuthenticate(*challenges)¶
Bases:
ChallengeListHeaderProxy-Authenticate header, as defined by RFC 9110.
- Parameters:
challenges (tuple[TokenChallenge | AuthParamChallenge, ...])
- class http_fields.ProxyAuthenticationInfo(*auth_params)¶
Bases:
AuthParamsHeaderProxy-Authentication-Info header, as defined by RFC 9110.
- class http_fields.ProxyAuthorization(credentials)¶
Bases:
CredentialsHeaderProxy-Authorization header, as defined by RFC 9110.
- Parameters:
credentials (TokenCredentials | AuthParamCredentials)
- class http_fields.ProxyStatus(*members)¶
Bases:
StructuredListHeaderProxy-Status header, as defined by RFC 9209. Each
membersitem identifies an intermediary (its bare value) and carries parameters such aserrorandnext-hop.- Parameters:
members (tuple[Item | InnerList, ...])
- class http_fields.Range(range_unit, *ranges)¶
Bases:
HeaderRange header, as defined by RFC 9110, e.g.
bytes=0-499,-500.- Parameters:
range_unit (RangeUnit)
ranges (tuple[IntRange | SuffixRange, ...])
- class http_fields.Referer(uri)¶
Bases:
UriHeaderReferer header, as defined by RFC 9110.
- Parameters:
uri (RefererUri)
- uri_type¶
alias of
RefererUri
- class http_fields.ReprDigest(*digests)¶
Bases:
DigestHeaderRepr-Digest header, as defined by RFC 9530: like Content-Digest, but over the selected representation.
- class http_fields.RetryAfter(delay)¶
Bases:
HeaderRetry-After header, as defined by RFC 9110. The delay is either a number of seconds (a NonNegativeInt) or an HTTP-date.
- Parameters:
delay (NonNegativeInt | datetime)
- class http_fields.Server(*items)¶
Bases:
ProductListHeaderServer header, as defined by RFC 9110.
itemsis a sequence of Product or Comment values.- Parameters:
items (tuple[Product | Comment, ...])
- class http_fields.SetCookie(*, cookie_name, cookie_value, domain=None, path=None, expires=None, max_age=None, secure=False, http_only=False, samesite=None, extension=())¶
Bases:
HeaderSet-Cookie header, as defined by RFC 6265.
Use
build()to construct (and validate) from pieces, orparse()to parse a raw header value with the lenient RFC 6265 section 5 algorithm.- Parameters:
- classmethod build(cookie_name, cookie_value, *, domain=None, path=None, expires=None, max_age=None, secure=False, http_only=False, samesite=None, extension=None)¶
Build a validated Set-Cookie from its pieces.
- class http_fields.StrictTransportSecurity(max_age, include_subdomains=False, preload=False)¶
Bases:
HeaderStrict-Transport-Security (HSTS) header, as defined by RFC 6797.
- Parameters:
max_age (NonNegativeInt)
include_subdomains (bool)
preload (bool)
- class http_fields.TCoding(coding, weight=None, parameters=())¶
Bases:
objectA single TE t-coding: a transfer-coding (or “trailers”) with an optional weight and transfer-parameters.
- class http_fields.TE(*codings)¶
Bases:
HeaderTE header, as defined by RFC 9110: the transfer-codings the client is willing to accept (plus the special
trailerstoken), each with an optional weight.
- class http_fields.Trailer(*field_names)¶
Bases:
HeaderTrailer header, as defined by RFC 9110.
- class http_fields.Upgrade(*protocols)¶
Bases:
HeaderUpgrade header, as defined by RFC 9110: a list of protocols, e.g.
HTTP/2, WebSocket.
- class http_fields.UserAgent(*items)¶
Bases:
ProductListHeaderUser-Agent header, as defined by RFC 9110.
itemsis a sequence of Product or Comment values.- Parameters:
items (tuple[Product | Comment, ...])
- class http_fields.Vary(*field_names)¶
Bases:
HeaderVary header, as defined by RFC 9110.
An empty
field_namesserializes as*(vary by anything).Vary: accept-encoding, accept-language
- class http_fields.Via(*elements)¶
Bases:
HeaderVia header, as defined by RFC 9110: the intermediaries a message passed through.
- Parameters:
elements (tuple[ViaElement, ...])
- class http_fields.WWWAuthenticate(*challenges)¶
Bases:
ChallengeListHeaderWWW-Authenticate header, as defined by RFC 9110.
- Parameters:
challenges (tuple[TokenChallenge | AuthParamChallenge, ...])
- class http_fields.ExtValue(*, charset: str = 'utf-8', language: str = '', value: str)¶
Bases:
object
- class http_fields.CookiePair(name: str, value: str)¶
Bases:
object- Parameters:
name (CookieName)
value (CookieValue)
- class http_fields.AltValue(protocol_id, authority, params=())¶
Bases:
objectOne RFC 7838 alt-value: a protocol-id, an alt-authority, and parameters.
- Parameters:
protocol_id (ProtocolId)
authority (AltAuthority)
params (tuple[Param, ...])
- class http_fields.ForwardedElement(pairs)¶
Bases:
objectOne Forwarded element (RFC 7239): an ordered sequence of
name=valuepairs, e.g.for=192.0.2.60;proto=http.- Parameters:
pairs (tuple[Param, ...])
- class http_fields.IntRange(first_pos, last_pos=None)¶
Bases:
objectAn RFC 9110 int-range, e.g.
0-499or500-(open-ended).- Parameters:
first_pos (NonNegativeInt)
last_pos (NonNegativeInt | None)
- class http_fields.LinkValue(target, params=())¶
Bases:
objectOne RFC 8288 link-value: a target URI reference plus link-params.
- Parameters:
target (URIReference)
params (tuple[Param, ...])
- class http_fields.Preference(name, value=None, parameters=())¶
Bases:
objectOne RFC 7240 preference: a token, an optional value, and optional parameters. Self-validating: an invalid name, value, or parameter cannot be built.
- class http_fields.SuffixRange(suffix_length)¶
Bases:
objectAn RFC 9110 suffix-range, e.g.
-500(the final N units).- Parameters:
suffix_length (NonNegativeInt)
- class http_fields.ViaElement(received_protocol, received_by, comment=None)¶
Bases:
objectOne hop in a Via header: a received-protocol, a received-by, and an optional comment.
- Parameters:
received_protocol (ReceivedProtocol)
received_by (ReceivedBy)
comment (Comment | None)
- class http_fields.WeightedCoding(coding: str, weight: float | http_fields.visitors.rfc9110.weight.Weight | None = None)¶
Bases:
object- Parameters:
coding (Coding)
weight (Weight | None)
- class http_fields.WeightedLanguageRange(language_range: str, weight: float | http_fields.visitors.rfc9110.weight.Weight | None = None)¶
Bases:
object- Parameters:
language_range (LanguageRange)
weight (Weight | None)
- class http_fields.CorsFieldName(s, parse=True)¶
Bases:
ParsedStrA CORS field-name. Self-validating.
- class http_fields.CorsMethod(s, parse=True)¶
Bases:
ParsedStrA CORS method token. Self-validating.
- class http_fields.Expectation(s, parse=True)¶
Bases:
ParsedStrAn RFC 9110 expectation (e.g.
100-continue). Self-validating.
- class http_fields.FieldName(s, parse=True)¶
Bases:
CaselessMixin,ParsedStrRepresents an RFC 9110 field name.