An implementation of HTTP-protocol parsing, formatting, and validation primitives per RFC 9110. More...
Classes | |
| struct | sourcemeta::core::HTTPLink |
| struct | sourcemeta::core::HTTPCookie |
| struct | sourcemeta::core::HTTPAWSCredentials |
| class | sourcemeta::core::HTTPError |
| class | sourcemeta::core::HTTPStatusError |
| struct | sourcemeta::core::HTTPProblemDetails |
| struct | sourcemeta::core::HTTPStatus |
| struct | sourcemeta::core::HTTPResponse |
| class | sourcemeta::core::HTTPSystemBackendError |
| class | sourcemeta::core::HTTPSystemRequest |
Enumerations | |
| enum class | sourcemeta::core::HTTPContentEncoding : std::uint8_t { HTTPContentEncoding::Identity , HTTPContentEncoding::GZIP } |
| enum class | sourcemeta::core::HTTPCookieSameSite : std::uint8_t { HTTPCookieSameSite::Strict , HTTPCookieSameSite::Lax , HTTPCookieSameSite::None } |
| enum class | sourcemeta::core::HTTPMethod : std::uint8_t { HTTPMethod::GET , HTTPMethod::HEAD , HTTPMethod::POST , HTTPMethod::PUT , HTTPMethod::DELETE , HTTPMethod::CONNECT , HTTPMethod::OPTIONS , HTTPMethod::TRACE , HTTPMethod::PATCH } |
Functions | |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_match_accept (const std::string_view accept_header, std::initializer_list< std::string_view > candidates) -> std::string_view |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_accept_includes_all (const std::string_view accept_header, std::initializer_list< std::string_view > media_types) noexcept -> bool |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_content_type_matches (const std::string_view content_type_header, const std::string_view media_type) noexcept -> bool |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_match_accept_language (const std::string_view accept_language_header, std::initializer_list< std::string_view > candidates) -> std::string_view |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_negotiate_encoding (const std::string_view accept_encoding_header, const HTTPContentEncoding server_preference) noexcept -> std::optional< HTTPContentEncoding > |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_from_date (const std::string_view value) noexcept -> std::optional< std::chrono::system_clock::time_point > |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_cache_control_max_age (const std::string_view cache_control) noexcept -> std::optional< std::chrono::seconds > |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_format_link (const HTTPLink &link, std::string &out) -> void |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_format_link (const HTTPLink &link) -> std::string |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_format_links (std::span< const HTTPLink > links, std::string &out) -> void |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_format_links (std::span< const HTTPLink > links) -> std::string |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_cookie_valid (const HTTPCookie &cookie) -> bool |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_serialize_cookie (const HTTPCookie &cookie, std::string &out) -> bool |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_serialize_cookie (const HTTPCookie &cookie) -> std::optional< std::string > |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_field_list_contains_any (const std::string_view header_value, std::initializer_list< std::string_view > tokens) noexcept -> bool |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_parse_bearer (const std::string_view authorization) noexcept -> std::string_view |
| auto SOURCEMETA_CORE_HTTP_EXPORT | sourcemeta::core::http_aws_sigv4_canonical_request (const std::string_view method, const std::string_view path, const std::string_view query, const std::span< const std::pair< std::string_view, std::string_view > > headers, const std::string_view payload_hash, const bool normalize=true) -> std::string |
| auto SOURCEMETA_CORE_HTTP_EXPORT | sourcemeta::core::http_aws_sigv4_signed_headers (const std::span< const std::pair< std::string_view, std::string_view > > headers) -> std::string |
| auto SOURCEMETA_CORE_HTTP_EXPORT | sourcemeta::core::http_aws_sigv4_credential_scope (const std::string_view date, const std::string_view region, const std::string_view service) -> std::string |
| auto SOURCEMETA_CORE_HTTP_EXPORT | sourcemeta::core::http_aws_sigv4_string_to_sign (const std::string_view amz_date, const std::string_view scope, const std::string_view canonical_request) -> std::string |
| auto SOURCEMETA_CORE_HTTP_EXPORT | sourcemeta::core::http_aws_sigv4_signing_key (const std::string_view secret, const std::string_view date, const std::string_view region, const std::string_view service) -> std::array< std::uint8_t, 32 > |
| auto SOURCEMETA_CORE_HTTP_EXPORT | sourcemeta::core::http_aws_sigv4_signature (const std::array< std::uint8_t, 32 > &signing_key, const std::string_view string_to_sign) -> std::string |
| auto SOURCEMETA_CORE_HTTP_EXPORT | sourcemeta::core::http_aws_sigv4_authorization (const std::string_view access_key_id, const std::string_view scope, const std::string_view signed_headers, const std::string_view signature) -> std::string |
| constexpr auto | sourcemeta::core::http_is_status_line (const std::string_view line) noexcept -> bool |
| template<typename Buffer> | |
| auto | sourcemeta::core::http_accumulate_header_line (Buffer &buffer, const std::string_view line) -> void |
| template<typename Callback> | |
| auto | sourcemeta::core::http_parse_headers (const std::string_view input, Callback callback) -> void |
| template<typename Callback> | |
| auto | sourcemeta::core::http_parse_cookies (const std::string_view input, Callback callback) -> void |
| template<typename Container> | |
| auto | sourcemeta::core::http_parse_cookies (const std::string_view input, Container &cookies) -> void |
| template<typename Container> | |
| auto | sourcemeta::core::http_cookie_values (const std::string_view input, const std::string_view name, Container &values) -> void |
| template<typename Container> | |
| auto | sourcemeta::core::http_parse_headers (const std::string_view input, Container &headers) -> void |
| template<typename Headers> | |
| auto | sourcemeta::core::http_serialize_headers (const Headers &headers) -> std::string |
| template<typename Headers> | |
| auto | sourcemeta::core::http_header_find (const Headers &headers, const std::string_view name) -> std::optional< std::string_view > |
| constexpr auto | sourcemeta::core::http_method_string (const HTTPMethod method) noexcept -> std::string_view |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_make_problem_details (const HTTPProblemDetails &problem) -> sourcemeta::core::JSON |
| constexpr auto | sourcemeta::core::http_status_from_code (const std::uint16_t code) noexcept -> HTTPStatus |
| auto | sourcemeta::core::http_is_ows (const char character) noexcept -> bool |
| auto | sourcemeta::core::http_is_tchar (const char character) noexcept -> bool |
| auto | sourcemeta::core::http_is_b64token_char (const char character) noexcept -> bool |
| auto | sourcemeta::core::http_is_b64token (const std::string_view value) noexcept -> bool |
| auto | sourcemeta::core::http_is_token (const std::string_view value) noexcept -> bool |
| auto | sourcemeta::core::http_encode_quoted_string (const std::string_view value, std::string &sink) -> bool |
| auto | sourcemeta::core::http_field_line_has_forbidden_byte (const std::string_view value) noexcept -> bool |
| auto | sourcemeta::core::http_trim_leading_ows (std::string_view value) noexcept -> std::string_view |
| auto | sourcemeta::core::http_trim_trailing_ows (std::string_view value) noexcept -> std::string_view |
| SOURCEMETA_CORE_HTTP_EXPORT auto | sourcemeta::core::http_scan_quoted_string (const std::string_view input, const std::size_t position, std::string &storage, std::string_view &value) -> std::optional< std::size_t > |
An implementation of HTTP-protocol parsing, formatting, and validation primitives per RFC 9110.
This functionality is included as follows:
| struct sourcemeta::core::HTTPLink |
A typed RFC 8288 §3 link-value. The caller owns the backing storage for every field, must URI-escape target, and must ensure parameter values are valid quoted-string content.
| struct sourcemeta::core::HTTPCookie |
A cookie to serialise into an RFC 6265 §4.1 Set-Cookie response header value. The caller owns the backing storage for every field. A valid cookie has a name that is an RFC 9110 §5.6.2 token and a value made of RFC 6265 §4.1.1 cookie-octets. RFC 6265bis §5.7 requires a cookie with a same-site mode of none to also be secure.
Public Attributes | |
| std::string_view | name {} |
| The cookie name. | |
| std::string_view | value {} |
| The cookie value. | |
| std::optional< std::string_view > | path {} |
| The path the cookie is scoped to. | |
| std::optional< std::string_view > | domain {} |
| The host the cookie is scoped to. | |
| std::optional< std::chrono::seconds > | max_age {} |
| The cookie lifetime. | |
| bool | http_only {false} |
| Whether the cookie is withheld from scripts. | |
| bool | secure {false} |
| Whether the cookie is only sent over secure channels. | |
| std::optional< HTTPCookieSameSite > | same_site {} |
| The cross-site request policy for the cookie. | |
| struct sourcemeta::core::HTTPAWSCredentials |
The credentials used to sign a request with AWS Signature Version 4. The session token is left empty when using long-term credentials.
| class sourcemeta::core::HTTPError |
An error that prevented obtaining a response, such as a connection failure, a name resolution failure, or a TLS failure. For example:
Public Member Functions | |
| HTTPError (const HTTPMethod method, std::string url, const std::string &message) | |
| Construct an error from the request method, URL, and a message. | |
| auto | method () const noexcept -> HTTPMethod |
| Get the request method that triggered the failure. | |
| auto | url () const noexcept -> const std::string & |
| Get the request URL that triggered the failure. | |
| class sourcemeta::core::HTTPStatusError |
An error for a response with an unsuccessful status code, owning a copy of the status data. For example:
Public Member Functions | |
| HTTPStatusError (const HTTPMethod method, std::string url, const HTTPStatus &status) | |
| auto | status () const noexcept -> HTTPStatus |
| Public Member Functions inherited from sourcemeta::core::HTTPError | |
| HTTPError (const HTTPMethod method, std::string url, const std::string &message) | |
| Construct an error from the request method, URL, and a message. | |
| auto | method () const noexcept -> HTTPMethod |
| Get the request method that triggered the failure. | |
| auto | url () const noexcept -> const std::string & |
| Get the request URL that triggered the failure. | |
|
inline |
Construct an error from the request method, URL, and the unsuccessful response status
|
inlinenodiscardnoexcept |
Get the response status that triggered the failure. The contained views borrow from this error and stay valid for its lifetime
| struct sourcemeta::core::HTTPProblemDetails |
Fields of an RFC 9457 §3.1 Problem Details object.
Public Attributes | |
| HTTPStatus | status |
| The HTTP status code for this occurrence of the problem. | |
| JSON::StringView | type {"about:blank"} |
| The identifier for the problem type. | |
| JSON::StringView | title {} |
| The short human-readable summary of the problem type. | |
| JSON::StringView | detail {} |
| The human-readable explanation specific to this occurrence. | |
| JSON::StringView | instance {} |
| The identifier for this specific occurrence of the problem. | |
| struct sourcemeta::core::HTTPStatus |
A typed HTTP status code per RFC 9110 §15. For example:
Public Attributes | |
| std::uint16_t | code |
| The numeric status code. | |
| std::string_view | phrase |
| The reason phrase. | |
| std::string_view | wire |
| The status code and reason phrase in their wire form. | |
| struct sourcemeta::core::HTTPResponse |
The result of performing a request against a system HTTP backend. For example:
Public Attributes | |
| HTTPStatus | status {} |
| The response status code. | |
| std::vector< std::pair< std::string, std::string > > | headers |
| std::string | body |
| The response body, owned by this result. | |
| std::string | url |
| The effective URL after any followed redirects. | |
| std::vector<std::pair<std::string, std::string> > sourcemeta::core::HTTPResponse::headers |
The response headers, with names normalised to lowercase. Repeated headers are preserved as separate entries, though some backends fold them into a single comma-separated entry, which is lossy and incorrect for a Set-Cookie header that "cannot be combined into a single field value" (RFC 9110 §5.3)
| class sourcemeta::core::HTTPSystemBackendError |
An error that prevented loading the underlying system HTTP backend, such as a missing dynamically loaded library. For example:
Public Member Functions | |
| HTTPSystemBackendError (const std::string &message, std::string variable, std::vector< std::string > paths) | |
| auto | variable () const noexcept -> const std::string & |
| Get the name of the environment variable that overrides the backend path. | |
| auto | paths () const noexcept -> const std::vector< std::string > & |
| Get the paths that were searched while looking for the backend. | |
|
inline |
Construct an error from a message, the environment variable that overrides the backend path, and the paths that were searched
| class sourcemeta::core::HTTPSystemRequest |
A simple cross-platform HTTP request that delegates to the system HTTP stack, NSURLSession on Apple platforms, WinHTTP on Windows, and cURL everywhere else. The request owns its data, configure it with the builder methods and perform it with send. For example:
Public Member Functions | |
| HTTPSystemRequest (std::string url, const HTTPMethod method=HTTPMethod::GET) | |
| Construct a request for the given URL and method. | |
| auto | method (const HTTPMethod method) -> HTTPSystemRequest & |
| Set the request method. | |
| auto | header (std::string name, std::string value) -> HTTPSystemRequest & |
| auto | header (std::string name, SecureString value) -> HTTPSystemRequest & |
| auto | header (const std::string_view name) const -> std::optional< std::string_view > |
| auto | headers () const noexcept -> const auto & |
| Get the request headers configured so far, in the order they were added. | |
| auto | body (std::string data, std::string content_type) -> HTTPSystemRequest & |
| auto | body (SecureString data, std::string content_type) -> HTTPSystemRequest & |
| auto | follow_redirects (const bool value) -> HTTPSystemRequest & |
| Set whether to follow redirects, on by default. | |
| auto | maximum_redirects (const std::size_t value) -> HTTPSystemRequest & |
| Set the maximum number of redirects to follow, 20 by default. | |
| auto | timeout (const std::chrono::milliseconds value) -> HTTPSystemRequest & |
| Set the total request timeout, 30 seconds by default. | |
| auto | connect_timeout (const std::chrono::milliseconds value) -> HTTPSystemRequest & |
| auto | maximum_response_size (const std::size_t value) -> HTTPSystemRequest & |
| Abort with an error if the response body exceeds this number of bytes. | |
| auto | sign_aws_sigv4 (const HTTPAWSCredentials &credentials, const std::string_view region, const std::string_view service, const std::chrono::system_clock::time_point moment=std::chrono::system_clock::now()) -> HTTPSystemRequest & |
| auto | send () const -> HTTPResponse |
|
inline |
Set the request body from wiping storage, sent along with the given Content-Type header. The body is held in the wiping storage so a secret it carries, such as a client secret or PKCE code verifier, is never copied into an ordinary string. A content type carrying a carriage return, line feed, or NUL is refused, leaving the request unchanged
|
inline |
Set the request body, sent along with the given Content-Type header. A content type carrying a carriage return, line feed, or NUL is refused, leaving the request unchanged
|
inline |
Set a best-effort timeout for establishing the connection, applied as each backend allows and falling back to the backend default when unset
|
inlinenodiscard |
Get the value of the first header with the given name, compared case insensitively, or no value when no such header was added. For example:
|
inline |
Add a request header from wiping storage. The value is held in the wiping storage so a secret it carries, such as a client credential, is never retained in an ordinary string, and the transient serialisation a backend builds at send time is wiped
|
inline |
Add a request header. Repeated names are permitted. A name or value carrying a carriage return, line feed, or NUL is refused, leaving the request unchanged
|
nodiscard |
Perform the request. A failure to obtain a response is reported as an error, while unsuccessful status codes are returned on the result. This blocks the calling thread until the response arrives or a timeout elapses, so it must not run on an event loop or any other thread serving unrelated work.
| auto sourcemeta::core::HTTPSystemRequest::sign_aws_sigv4 | ( | const HTTPAWSCredentials & | credentials, |
| const std::string_view | region, | ||
| const std::string_view | service, | ||
| const std::chrono::system_clock::time_point | moment = std::chrono::system_clock::now() ) -> HTTPSystemRequest & |
Sign this request with AWS Signature Version 4, stamping the x-amz-date, x-amz-content-sha256, and Authorization headers, plus x-amz-security-token when the credentials carry a session token. The path is normalised for every service except Amazon S3. The timestamp defaults to the current time. For example:
|
strong |
|
strong |
|
strong |
A request method per RFC 9110 §9.3 and RFC 5789 §2.
|
noexcept |
Test whether every media type is individually acceptable under an Accept header per RFC 9110 §12.5.1. For example:
|
inline |
Accumulate raw header lines into a buffer, retaining only the block of the most recent message, given that transparently following redirects or receiving interim responses produces one header block per message. For example:
| auto SOURCEMETA_CORE_HTTP_EXPORT sourcemeta::core::http_aws_sigv4_authorization | ( | const std::string_view | access_key_id, |
| const std::string_view | scope, | ||
| const std::string_view | signed_headers, | ||
| const std::string_view | signature ) -> std::string |
Assemble the AWS Signature Version 4 Authorization header value from an access key, credential scope, signed headers, and signature. For example:
| auto SOURCEMETA_CORE_HTTP_EXPORT sourcemeta::core::http_aws_sigv4_canonical_request | ( | const std::string_view | method, |
| const std::string_view | path, | ||
| const std::string_view | query, | ||
| const std::span< const std::pair< std::string_view, std::string_view > > | headers, | ||
| const std::string_view | payload_hash, | ||
| const bool | normalize = true ) -> std::string |
Compute the AWS Signature Version 4 canonical request from a request method, path, query, headers, and payload hash. Each path segment and query parameter is decoded and re-encoded into canonical form, so the path and query may be passed exactly as they appear in the request target. The path is optionally normalised by collapsing sequential slashes and removing dot segments, which every service except Amazon S3 requires. For example:
| auto SOURCEMETA_CORE_HTTP_EXPORT sourcemeta::core::http_aws_sigv4_credential_scope | ( | const std::string_view | date, |
| const std::string_view | region, | ||
| const std::string_view | service ) -> std::string |
Compute the AWS Signature Version 4 credential scope from a date, region, and service. For example:
| auto SOURCEMETA_CORE_HTTP_EXPORT sourcemeta::core::http_aws_sigv4_signature | ( | const std::array< std::uint8_t, 32 > & | signing_key, |
| const std::string_view | string_to_sign ) -> std::string |
Compute the AWS Signature Version 4 hex signature from a signing key and a string to sign. For example:
| auto SOURCEMETA_CORE_HTTP_EXPORT sourcemeta::core::http_aws_sigv4_signed_headers | ( | const std::span< const std::pair< std::string_view, std::string_view > > | headers | ) | -> std::string |
Compute the AWS Signature Version 4 signed headers list, the lowercased header names sorted and joined with a semicolon. For example:
| auto SOURCEMETA_CORE_HTTP_EXPORT sourcemeta::core::http_aws_sigv4_signing_key | ( | const std::string_view | secret, |
| const std::string_view | date, | ||
| const std::string_view | region, | ||
| const std::string_view | service ) -> std::array< std::uint8_t, 32 > |
Derive the AWS Signature Version 4 signing key from a secret access key, date, region, and service. For example:
| auto SOURCEMETA_CORE_HTTP_EXPORT sourcemeta::core::http_aws_sigv4_string_to_sign | ( | const std::string_view | amz_date, |
| const std::string_view | scope, | ||
| const std::string_view | canonical_request ) -> std::string |
Compute the AWS Signature Version 4 string to sign from a timestamp, a credential scope, and a canonical request. For example:
|
noexcept |
Read the max-age response directive from a Cache-Control header value per RFC 9111 §5.2.2.1. Returns an empty value when the directive is absent or malformed. A value larger than the cache can represent saturates to 2147483648 seconds as mandated by RFC 9111 §1.2.2. For example:
|
noexcept |
Test whether a Content-Type header denotes the given media type per RFC 9110 §8.3.1. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_cookie_valid | ( | const HTTPCookie & | cookie | ) | -> bool |
Test whether a cookie can be serialised into a valid RFC 6265 §4.1 Set-Cookie header value: the name is a non-empty RFC 9110 §5.6.2 token, the value is made of RFC 6265 §4.1.1 cookie-octets, any path is made of RFC 6265bis av-octets, any domain is a valid RFC 1123 host name allowing an ignorable leading dot, a present max_age is not negative, per RFC 6265bis §5.7 a HTTPCookieSameSite::None cookie is also secure, and the RFC 6265bis §4.1.3 __Secure- and __Host- name prefixes carry their required attributes. For example:
|
inline |
Collect every value carried under the given cookie name, in the order the header presents them. A request may carry several cookies with one name, since a parent domain and the host itself can each set one and RFC 6265 §4.2.2 notes the server "cannot determine from the Cookie header alone [...] for which hosts the cookie is valid". That section also warns that servers "SHOULD NOT rely upon the order in which these cookies appear", so a caller verifying a signed cookie tries every value rather than any single one. Naming a cookie with the RFC 6265bis §4.1.3.2 __Host- prefix prevents the collision at the source.
The values are borrowed from input rather than copied, so a container of views must not outlive it, while an owning container may. For example:
|
inline |
Append a string to the sink as a quoted-string (RFC 9110 Section 5.6.4), wrapping it in double quotes and escaping any double quote or backslash, returning whether it was encodable. Nothing is appended when the string carries a byte no quoted-string admits, such as a control character, which keeps a value from injecting into a header. For example:
|
inlinenoexcept |
Whether a field name or value carries a byte that must never appear on a field line, a carriage return, a line feed, or a NUL (RFC 9110 Section 5.5). For example:
|
noexcept |
Test whether a comma-separated header value per RFC 9110 §5.6.1 lists any of the given tokens. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_format_link | ( | const HTTPLink & | link | ) | -> std::string |
Format an RFC 8288 §3 link-value. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_format_link | ( | const HTTPLink & | link, |
| std::string & | out ) -> void |
Append an RFC 8288 §3 link-value to out. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_format_links | ( | std::span< const HTTPLink > | links | ) | -> std::string |
Format an RFC 8288 §3.5 comma-separated multi-link value. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_format_links | ( | std::span< const HTTPLink > | links, |
| std::string & | out ) -> void |
Append an RFC 8288 §3.5 comma-separated multi-link value to out. For example:
|
noexcept |
Parse an HTTP-date string per RFC 9110 §5.6.7. For example:
|
inline |
Find the value of the first header with the given lowercase name in any range of name and value pairs, returning no result when absent. For example:
|
inlinenoexcept |
Whether a string is a well-formed token68 (RFC 7235 Section 2.1) or b64token (RFC 6750 Section 2.1), at least one alphabet character followed by any "=" padding. For example:
|
inlinenoexcept |
Whether a character may appear in the alphabet of a token68 (RFC 7235 Section 2.1) or b64token (RFC 6750 Section 2.1) credential, before its padding. For example:
|
inlinenoexcept |
Whether a character is optional whitespace, a space or a horizontal tab (RFC 9110 Section 5.6.3). For example:
|
inlineconstexprnoexcept |
Test whether a raw line opens a message header block per RFC 9112 §4. For example:
|
inlinenoexcept |
Whether a character is a token character (RFC 9110 Section 5.6.2), the set a bare header token draws from. For example:
|
inlinenoexcept |
Whether a string is a well-formed token (RFC 9110 Section 5.6.2), at least one token character and nothing else. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_make_problem_details | ( | const HTTPProblemDetails & | problem | ) | -> sourcemeta::core::JSON |
Build an RFC 9457 §3.1 Problem Details JSON object. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_match_accept | ( | const std::string_view | accept_header, |
| std::initializer_list< std::string_view > | candidates ) -> std::string_view |
Pick the best media-type candidate against an Accept header per RFC 9110 §12.5.1. Returns an empty value when no candidate is acceptable. The returned view borrows from candidates. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_match_accept_language | ( | const std::string_view | accept_language_header, |
| std::initializer_list< std::string_view > | candidates ) -> std::string_view |
Pick the best language-tag candidate against an Accept-Language header per RFC 9110 §12.5.4, which lets an implementation choose its matching scheme. This uses a q-aware Basic-Filtering-style scheme (RFC 4647 §3.3.1, the scheme RFC 9110 §12.5.4 points to) that also honors q=0 exclusions. Returns an empty value when no candidate is acceptable. The returned view borrows from candidates. For example:
|
inlineconstexprnoexcept |
Convert a request method into its case-sensitive token per RFC 9110 §9.1. For example:
|
noexcept |
Resolve a content coding against an Accept-Encoding header per RFC 9110 §12.5.3. For example:
|
noexcept |
Extract the credential from an Authorization header that uses the Bearer scheme per RFC 6750 §2.1, matching the scheme case-insensitively per RFC 9110 §11.1 and tolerating optional whitespace around the token. Returns an empty view when the header is absent, uses another scheme, or does not carry a well-formed b64token credential. For example:
|
inline |
Parse the value of an RFC 6265 §4.2 Cookie request header, given without the field name, into its cookie-pairs, invoking the callback once per pair with the name and value. A request cookie header carries only names and values, never attributes. Surrounding whitespace is trimmed, values are otherwise reported verbatim, and pairs that lack a = or have an empty name are skipped. Neither argument allocates, as both are borrowed from the input, so anything the callback keeps must not outlive it. For example:
A header may carry several cookies under one name, so a callback that assigns to a single variable keeps whichever happens to come last. Use http_cookie_values to look one up by name.
|
inline |
Parse the value of an RFC 6265 §4.2 Cookie request header, given without the field name, into any container of name and value pairs. The names and values are borrowed from input rather than copied, so a container of views must not outlive it, while an owning container may. For example:
|
inline |
Parse the field lines of a raw message header block per RFC 9112 §5, skipping the start line and invoking the callback with each raw field name and its value with optional whitespace excluded. A continuation of the previous value through deprecated line folding is reported with an empty name. Malformed field lines are discarded. Neither argument allocates, as both are views into the input. For example:
|
inline |
Parse the field lines of a raw message header block, skipping the start line, into any container of name and value pairs, normalising names to lowercase given that RFC 9110 §5.1 mandates that "field names are case-insensitive", preserving repeated fields as separate entries, and joining deprecated line folding per RFC 9112 §5.2. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_scan_quoted_string | ( | const std::string_view | input, |
| const std::size_t | position, | ||
| std::string & | storage, | ||
| std::string_view & | value ) -> std::optional< std::size_t > |
Scan a quoted-string (RFC 9110 Section 5.6.4) whose opening double quote is at position in input, returning the position just past the closing quote, or no value when it is malformed. The unescaped content is written to value, borrowing from input when it carries no quoted-pair and appending to storage otherwise, whose capacity should be reserved up front so that earlier views into it stay valid. Control characters other than horizontal tab are rejected as a header-injection defense. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_serialize_cookie | ( | const HTTPCookie & | cookie | ) | -> std::optional< std::string > |
Serialise an RFC 6265 §4.1 Set-Cookie header value, returning no value when the cookie is not http_cookie_valid. For example:
| SOURCEMETA_CORE_HTTP_EXPORT auto sourcemeta::core::http_serialize_cookie | ( | const HTTPCookie & | cookie, |
| std::string & | out ) -> bool |
Append an RFC 6265 §4.1 Set-Cookie header value to out, returning true on success. When the cookie is not http_cookie_valid, out is left unchanged and this returns false. For example:
|
inline |
Serialise headers, given as any range of name and value pairs, into CRLF-delimited field lines per RFC 9112 §5. For example:
|
inlineconstexprnoexcept |
Resolve a numeric status code into its registered status, with unknown codes resolving to an empty reason phrase. For example:
|
inlinenoexcept |
The view with any leading optional whitespace removed (RFC 9110 Section 5.6.3). For example:
|
inlinenoexcept |
The view with any trailing optional whitespace removed (RFC 9110 Section 5.6.3). For example:
|
inlineconstexpr |
RFC 9110 §15.3.3 (Successful).
|
inlineconstexpr |
RFC 5842 §7.1 (WebDAV).
|
inlineconstexpr |
RFC 9110 §15.6.3 (Server Error).
|
inlineconstexpr |
RFC 9110 §15.5.1 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.5.10 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.5.14 (Client Error). RFC 9110 renamed this from "Payload Too Large" (RFC 7231) to "Content Too Large".
|
inlineconstexpr |
RFC 9110 §15.2.1 (Informational).
|
inlineconstexpr |
RFC 9110 §15.3.2 (Successful).
|
inlineconstexpr |
RFC 8297 §2.
|
inlineconstexpr |
RFC 9110 §15.5.18 (Client Error).
|
inlineconstexpr |
RFC 4918 §11.4 (WebDAV).
|
inlineconstexpr |
RFC 9110 §15.5.4 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.4.3 (Redirection).
|
inlineconstexpr |
RFC 9110 §15.6.5 (Server Error).
|
inlineconstexpr |
RFC 9110 §15.5.11 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.6.6 (Server Error).
|
inlineconstexpr |
RFC 2324 §2.3.2 (HTCPCP).
|
inlineconstexpr |
RFC 3229 §10.4.1 (HTTP Delta Encoding).
|
inlineconstexpr |
RFC 4918 §11.5 (WebDAV).
|
inlineconstexpr |
RFC 9110 §15.6.1 (Server Error).
|
inlineconstexpr |
RFC 9110 §15.5.12 (Client Error).
|
inlineconstexpr |
RFC 4918 §11.3 (WebDAV).
|
inlineconstexpr |
RFC 5842 §7.2 (WebDAV).
|
inlineconstexpr |
RFC 9110 §15.5.6 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.5.20 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.4.2 (Redirection).
|
inlineconstexpr |
RFC 4918 §11.1 (WebDAV).
|
inlineconstexpr |
RFC 9110 §15.4.1 (Redirection).
|
inlineconstexpr |
RFC 6585 §6.
|
inlineconstexpr |
RFC 9110 §15.3.5 (Successful).
|
inlineconstexpr |
RFC 9110 §15.3.4 (Successful).
|
inlineconstexpr |
RFC 9110 §15.5.7 (Client Error).
|
inlineconstexpr |
RFC 2774 §7.
|
inlineconstexpr |
RFC 9110 §15.5.5 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.6.2 (Server Error).
|
inlineconstexpr |
RFC 9110 §15.4.5 (Redirection).
|
inlineconstexpr |
RFC 9110 §15.3.1 (Successful).
|
inlineconstexpr |
RFC 9110 §15.3.7 (Successful).
|
inlineconstexpr |
RFC 9110 §15.5.3 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.4.9 (Redirection).
|
inlineconstexpr |
RFC 9110 §15.5.13 (Client Error).
|
inlineconstexpr |
RFC 6585 §3.
|
inlineconstexpr |
RFC 2518 §10.1 (WebDAV).
|
inlineconstexpr |
RFC 9110 §15.5.8 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.5.17 (Client Error).
|
inlineconstexpr |
RFC 6585 §5.
|
inlineconstexpr |
RFC 9110 §15.5.9 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.3.6 (Successful).
|
inlineconstexpr |
RFC 9110 §15.4.4 (Redirection).
|
inlineconstexpr |
RFC 9110 §15.6.4 (Server Error).
|
inlineconstexpr |
RFC 9110 §15.2.2 (Informational).
|
inlineconstexpr |
RFC 9110 §15.4.8 (Redirection).
|
inlineconstexpr |
RFC 8470 §5.2.
|
inlineconstexpr |
RFC 6585 §4.
|
inlineconstexpr |
RFC 9110 §15.5.2 (Client Error).
|
inlineconstexpr |
RFC 7725 §3.
|
inlineconstexpr |
RFC 9110 §15.5.21 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.5.16 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.5.22 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.5.15 (Client Error).
|
inlineconstexpr |
RFC 9110 §15.4.6 (Redirection).
|
inlineconstexpr |
RFC 2295 §8.1 (Transparent Content Negotiation).