Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
http.h
1#ifndef SOURCEMETA_CORE_HTTP_H_
2#define SOURCEMETA_CORE_HTTP_H_
3
4#ifndef SOURCEMETA_CORE_HTTP_EXPORT
5#include <sourcemeta/core/http_export.h>
6#endif
7
8// NOLINTBEGIN(misc-include-cleaner)
9#include <sourcemeta/core/http_aws_sigv4.h>
10#include <sourcemeta/core/http_baggage.h>
11#include <sourcemeta/core/http_error.h>
12#include <sourcemeta/core/http_message.h>
13#include <sourcemeta/core/http_method.h>
14#include <sourcemeta/core/http_problem.h>
15#include <sourcemeta/core/http_status.h>
16#include <sourcemeta/core/http_syntax.h>
17#include <sourcemeta/core/http_system.h>
18#include <sourcemeta/core/http_tracecontext.h>
19// NOLINTEND(misc-include-cleaner)
20
21#include <chrono> // std::chrono::system_clock
22#include <cstddef> // std::size_t
23#include <cstdint> // std::uint8_t
24#include <initializer_list> // std::initializer_list
25#include <optional> // std::optional
26#include <span> // std::span
27#include <string> // std::string
28#include <string_view> // std::string_view
29#include <utility> // std::pair
30#include <vector> // std::vector
31
50
51namespace sourcemeta::core {
52
55enum class HTTPContentEncoding : std::uint8_t {
60};
61
76SOURCEMETA_CORE_HTTP_EXPORT
77auto http_match_accept(const std::string_view accept_header,
78 std::initializer_list<std::string_view> candidates)
79 -> std::string_view;
80
95SOURCEMETA_CORE_HTTP_EXPORT
97 const std::string_view accept_header,
98 std::initializer_list<std::string_view> media_types) noexcept -> bool;
99
113SOURCEMETA_CORE_HTTP_EXPORT
114auto http_content_type_matches(const std::string_view content_type_header,
115 const std::string_view media_type) noexcept
116 -> bool;
117
123 std::string_view type{};
125 std::string_view subtype{};
129 std::string_view suffix{};
131 std::string_view parameters{};
132};
133
152SOURCEMETA_CORE_HTTP_EXPORT
153auto http_parse_media_type(const std::string_view media_type)
154 -> std::optional<HTTPMediaType>;
155
177SOURCEMETA_CORE_HTTP_EXPORT
178auto http_match_media_range(const std::string_view media_type,
179 std::span<const std::string_view> ranges) noexcept
180 -> std::string_view;
181
198SOURCEMETA_CORE_HTTP_EXPORT
200 const std::string_view accept_language_header,
201 std::initializer_list<std::string_view> candidates) -> std::string_view;
202
216SOURCEMETA_CORE_HTTP_EXPORT
218 const std::string_view accept_encoding_header,
219 const HTTPContentEncoding server_preference) noexcept
220 -> std::optional<HTTPContentEncoding>;
221
236SOURCEMETA_CORE_HTTP_EXPORT
237auto http_from_date(const std::string_view value)
238 -> std::optional<std::chrono::system_clock::time_point>;
239
256SOURCEMETA_CORE_HTTP_EXPORT
257auto http_cache_control_max_age(const std::string_view cache_control) noexcept
258 -> std::optional<std::chrono::seconds>;
259
264struct HTTPLink {
266 std::string_view target;
268 std::string_view rel;
270 std::span<const std::pair<std::string_view, std::string_view>> parameters{};
271};
272
286SOURCEMETA_CORE_HTTP_EXPORT
287auto http_format_link(const HTTPLink &link, std::string &out) -> void;
288
301SOURCEMETA_CORE_HTTP_EXPORT
302auto http_format_link(const HTTPLink &link) -> std::string;
303
321SOURCEMETA_CORE_HTTP_EXPORT
322auto http_format_links(std::span<const HTTPLink> links, std::string &out)
323 -> void;
324
339SOURCEMETA_CORE_HTTP_EXPORT
340auto http_format_links(std::span<const HTTPLink> links) -> std::string;
341
346enum class HTTPCacheVisibility : std::uint8_t {
354};
355
365 std::optional<HTTPCacheVisibility> visibility{};
367 std::optional<std::chrono::seconds> max_age{};
370 std::optional<std::chrono::seconds> shared_max_age{};
372 bool no_store{false};
375 bool no_cache{false};
378 bool must_revalidate{false};
380 bool proxy_revalidate{false};
383 bool must_understand{false};
385 bool no_transform{false};
387 bool immutable{false};
390 std::span<const std::string_view> private_fields{};
393 std::span<const std::string_view> no_cache_fields{};
394};
395
403SOURCEMETA_CORE_HTTP_EXPORT
404auto http_cache_control_valid(const HTTPCacheControl &directives) -> bool;
405
429SOURCEMETA_CORE_HTTP_EXPORT
431 std::string &out) -> bool;
432
445SOURCEMETA_CORE_HTTP_EXPORT
447 -> std::optional<std::string>;
448
458 std::string_view scheme{};
460 std::optional<std::string_view> token68{};
462 std::span<const std::pair<std::string_view, std::string_view>> parameters{};
463};
464
489SOURCEMETA_CORE_HTTP_EXPORT
490auto http_challenge_valid(const HTTPChallenge &challenge) -> bool;
491
518SOURCEMETA_CORE_HTTP_EXPORT
519auto http_serialize_challenge(const HTTPChallenge &challenge, std::string &out)
520 -> bool;
521
525SOURCEMETA_CORE_HTTP_EXPORT
527 -> std::optional<std::string>;
528
534SOURCEMETA_CORE_HTTP_EXPORT
535auto http_serialize_challenges(std::span<const HTTPChallenge> challenges,
536 std::string &out) -> bool;
537
557SOURCEMETA_CORE_HTTP_EXPORT
558auto http_serialize_challenges(std::span<const HTTPChallenge> challenges)
559 -> std::optional<std::string>;
560
568 std::string scheme;
570 std::optional<std::string> token68;
572 std::vector<std::pair<std::string, std::string>> parameters;
573};
574
604SOURCEMETA_CORE_HTTP_EXPORT
605auto http_parse_challenges(const std::string_view input,
606 std::vector<HTTPParsedChallenge> &challenges)
607 -> bool;
608
611enum class HTTPCookieSameSite : std::uint8_t {
618};
619
628 std::string_view name{};
630 std::string_view value{};
632 std::optional<std::string_view> path{};
634 std::optional<std::string_view> domain{};
636 std::optional<std::chrono::seconds> max_age{};
638 bool http_only{false};
640 bool secure{false};
642 std::optional<HTTPCookieSameSite> same_site{};
643};
644
651inline constexpr std::size_t HTTP_COOKIE_MAXIMUM_NAME_VALUE_LENGTH{4096};
652
657inline constexpr std::size_t HTTP_COOKIE_MAXIMUM_ATTRIBUTE_VALUE_LENGTH{1024};
658
678SOURCEMETA_CORE_HTTP_EXPORT
679auto http_cookie_valid(const HTTPCookie &cookie) -> bool;
680
697SOURCEMETA_CORE_HTTP_EXPORT
698auto http_serialize_cookie(const HTTPCookie &cookie, std::string &out) -> bool;
699
712SOURCEMETA_CORE_HTTP_EXPORT
714 -> std::optional<std::string>;
715
732SOURCEMETA_CORE_HTTP_EXPORT
734
748SOURCEMETA_CORE_HTTP_EXPORT
750 const std::string_view header_value,
751 std::initializer_list<std::string_view> tokens) noexcept -> bool;
752
777SOURCEMETA_CORE_HTTP_EXPORT
778auto http_format_vary(std::span<const std::string_view> field_names,
779 std::string &out) -> bool;
780
798SOURCEMETA_CORE_HTTP_EXPORT
799auto http_format_vary(std::span<const std::string_view> field_names)
800 -> std::optional<std::string>;
801
816SOURCEMETA_CORE_HTTP_EXPORT
817auto http_parse_bearer(const std::string_view authorization) noexcept
818 -> std::string_view;
819
820} // namespace sourcemeta::core
821
822#endif
std::string_view rel
The link relation type.
Definition http.h:268
std::vector< std::pair< std::string, std::string > > parameters
The authentication parameters, in the order they appeared.
Definition http.h:572
std::optional< std::string_view > token68
The credential the challenge carries in place of parameters.
Definition http.h:460
bool no_store
Whether no cache may store any part of the exchange (RFC 9111 §5.2.2.5).
Definition http.h:372
std::span< const std::string_view > private_fields
Definition http.h:390
bool proxy_revalidate
The same for a shared cache alone (RFC 9111 §5.2.2.8).
Definition http.h:380
bool secure
Whether the cookie is only sent over secure channels.
Definition http.h:640
std::optional< std::chrono::seconds > max_age
The cookie lifetime.
Definition http.h:636
std::span< const std::string_view > no_cache_fields
Definition http.h:393
std::string_view parameters
The parameters that follow the type, starting at the first ;.
Definition http.h:131
bool http_only
Whether the cookie is withheld from scripts.
Definition http.h:638
std::optional< std::string > token68
The credential the challenge carried in place of parameters.
Definition http.h:570
std::optional< std::string_view > domain
The host the cookie is scoped to.
Definition http.h:634
bool no_cache
Definition http.h:375
std::string scheme
The authentication scheme, as spelled in the field.
Definition http.h:568
std::optional< std::chrono::seconds > max_age
How long the response stays fresh (RFC 9111 §5.2.2.1).
Definition http.h:367
std::string_view name
The cookie name.
Definition http.h:628
bool must_revalidate
Definition http.h:378
std::span< const std::pair< std::string_view, std::string_view > > parameters
The authentication parameters.
Definition http.h:462
bool immutable
Whether the response will not be updated while fresh (RFC 8246).
Definition http.h:387
std::span< const std::pair< std::string_view, std::string_view > > parameters
The additional target attributes of the link.
Definition http.h:270
std::optional< HTTPCacheVisibility > visibility
Which caches may store the response.
Definition http.h:365
std::optional< HTTPCookieSameSite > same_site
The cross-site request policy for the cookie.
Definition http.h:642
std::string_view subtype
The subtype, such as geo+json.
Definition http.h:125
std::optional< std::chrono::seconds > shared_max_age
Definition http.h:370
bool must_understand
Definition http.h:383
std::optional< std::string_view > path
The path the cookie is scoped to.
Definition http.h:632
std::string_view target
The link target reference.
Definition http.h:266
std::string_view type
The type, such as application.
Definition http.h:123
std::string_view value
The cookie value.
Definition http.h:630
bool no_transform
Whether the payload must not be transformed (RFC 9111 §5.2.2.6).
Definition http.h:385
std::string_view suffix
Definition http.h:129
std::string_view scheme
The authentication scheme.
Definition http.h:458
HTTPCacheVisibility
Definition http.h:346
SOURCEMETA_CORE_HTTP_EXPORT auto 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 http_field_list_contains_any(const std::string_view header_value, std::initializer_list< std::string_view > tokens) noexcept -> bool
HTTPCookieSameSite
Definition http.h:611
SOURCEMETA_CORE_HTTP_EXPORT auto http_cache_control_valid(const HTTPCacheControl &directives) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_parse_media_type(const std::string_view media_type) -> std::optional< HTTPMediaType >
SOURCEMETA_CORE_HTTP_EXPORT auto http_parse_bearer(const std::string_view authorization) noexcept -> std::string_view
SOURCEMETA_CORE_HTTP_EXPORT auto http_serialize_challenge(const HTTPChallenge &challenge, std::string &out) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_match_accept(const std::string_view accept_header, std::initializer_list< std::string_view > candidates) -> std::string_view
SOURCEMETA_CORE_HTTP_EXPORT auto http_serialize_cookie(const HTTPCookie &cookie, std::string &out) -> bool
constexpr std::size_t HTTP_COOKIE_MAXIMUM_ATTRIBUTE_VALUE_LENGTH
Definition http.h:657
constexpr std::size_t HTTP_COOKIE_MAXIMUM_NAME_VALUE_LENGTH
Definition http.h:651
SOURCEMETA_CORE_HTTP_EXPORT auto http_content_type_matches(const std::string_view content_type_header, const std::string_view media_type) noexcept -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_match_media_range(const std::string_view media_type, std::span< const std::string_view > ranges) noexcept -> std::string_view
SOURCEMETA_CORE_HTTP_EXPORT auto http_format_links(std::span< const HTTPLink > links, std::string &out) -> void
SOURCEMETA_CORE_HTTP_EXPORT auto http_challenge_valid(const HTTPChallenge &challenge) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_expire_cookie(const HTTPCookie &cookie) -> HTTPCookie
SOURCEMETA_CORE_HTTP_EXPORT auto http_negotiate_encoding(const std::string_view accept_encoding_header, const HTTPContentEncoding server_preference) noexcept -> std::optional< HTTPContentEncoding >
SOURCEMETA_CORE_HTTP_EXPORT auto http_serialize_challenges(std::span< const HTTPChallenge > challenges, std::string &out) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_format_vary(std::span< const std::string_view > field_names, std::string &out) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_format_link(const HTTPLink &link, std::string &out) -> void
SOURCEMETA_CORE_HTTP_EXPORT auto http_parse_challenges(const std::string_view input, std::vector< HTTPParsedChallenge > &challenges) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto 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 http_cookie_valid(const HTTPCookie &cookie) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_from_date(const std::string_view value) -> std::optional< std::chrono::system_clock::time_point >
HTTPContentEncoding
Definition http.h:55
SOURCEMETA_CORE_HTTP_EXPORT auto http_serialize_cache_control(const HTTPCacheControl &directives, std::string &out) -> bool
SOURCEMETA_CORE_HTTP_EXPORT auto http_cache_control_max_age(const std::string_view cache_control) noexcept -> std::optional< std::chrono::seconds >
@ Strict
The cookie is withheld from every cross-site request.
Definition http.h:613
@ None
The cookie is sent on every cross-site request.
Definition http.h:617
@ Lax
The cookie is sent on top-level cross-site navigations only.
Definition http.h:615
Definition http.h:456
Definition http.h:626
Definition http.h:121
@ Identity
The contents are stored as they are.
Definition metapack_format.h:25
@ GZIP
The contents are stored compressed as per RFC 1952.
Definition metapack_format.h:27