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_error.h>
11#include <sourcemeta/core/http_message.h>
12#include <sourcemeta/core/http_method.h>
13#include <sourcemeta/core/http_problem.h>
14#include <sourcemeta/core/http_status.h>
15#include <sourcemeta/core/http_syntax.h>
16#include <sourcemeta/core/http_system.h>
17// NOLINTEND(misc-include-cleaner)
18
19#include <chrono> // std::chrono::system_clock
20#include <cstdint> // std::uint8_t
21#include <initializer_list> // std::initializer_list
22#include <optional> // std::optional
23#include <span> // std::span
24#include <string> // std::string
25#include <string_view> // std::string_view
26#include <utility> // std::pair
27
37
38namespace sourcemeta::core {
39
42enum class HTTPContentEncoding : std::uint8_t {
47};
48
63SOURCEMETA_CORE_HTTP_EXPORT
64auto http_match_accept(const std::string_view accept_header,
65 std::initializer_list<std::string_view> candidates)
66 -> std::string_view;
67
82SOURCEMETA_CORE_HTTP_EXPORT
84 const std::string_view accept_header,
85 std::initializer_list<std::string_view> media_types) noexcept -> bool;
86
100SOURCEMETA_CORE_HTTP_EXPORT
101auto http_content_type_matches(const std::string_view content_type_header,
102 const std::string_view media_type) noexcept
103 -> bool;
104
121SOURCEMETA_CORE_HTTP_EXPORT
123 const std::string_view accept_language_header,
124 std::initializer_list<std::string_view> candidates) -> std::string_view;
125
139SOURCEMETA_CORE_HTTP_EXPORT
141 const std::string_view accept_encoding_header,
142 const HTTPContentEncoding server_preference) noexcept
143 -> std::optional<HTTPContentEncoding>;
144
159SOURCEMETA_CORE_HTTP_EXPORT
160auto http_from_date(const std::string_view value) noexcept
161 -> std::optional<std::chrono::system_clock::time_point>;
162
179SOURCEMETA_CORE_HTTP_EXPORT
180auto http_cache_control_max_age(const std::string_view cache_control) noexcept
181 -> std::optional<std::chrono::seconds>;
182
187struct HTTPLink {
189 std::string_view target;
191 std::string_view rel;
193 std::span<const std::pair<std::string_view, std::string_view>> parameters{};
194};
195
209SOURCEMETA_CORE_HTTP_EXPORT
210auto http_format_link(const HTTPLink &link, std::string &out) -> void;
211
224SOURCEMETA_CORE_HTTP_EXPORT
225auto http_format_link(const HTTPLink &link) -> std::string;
226
244SOURCEMETA_CORE_HTTP_EXPORT
245auto http_format_links(std::span<const HTTPLink> links, std::string &out)
246 -> void;
247
262SOURCEMETA_CORE_HTTP_EXPORT
263auto http_format_links(std::span<const HTTPLink> links) -> std::string;
264
267enum class HTTPCookieSameSite : std::uint8_t {
274};
275
284 std::string_view name{};
286 std::string_view value{};
288 std::optional<std::string_view> path{};
290 std::optional<std::string_view> domain{};
292 std::optional<std::chrono::seconds> max_age{};
294 bool http_only{false};
296 bool secure{false};
298 std::optional<HTTPCookieSameSite> same_site{};
299};
300
318SOURCEMETA_CORE_HTTP_EXPORT
319auto http_cookie_valid(const HTTPCookie &cookie) -> bool;
320
337SOURCEMETA_CORE_HTTP_EXPORT
338auto http_serialize_cookie(const HTTPCookie &cookie, std::string &out) -> bool;
339
352SOURCEMETA_CORE_HTTP_EXPORT
354 -> std::optional<std::string>;
355
369SOURCEMETA_CORE_HTTP_EXPORT
371 const std::string_view header_value,
372 std::initializer_list<std::string_view> tokens) noexcept -> bool;
373
388SOURCEMETA_CORE_HTTP_EXPORT
389auto http_parse_bearer(const std::string_view authorization) noexcept
390 -> std::string_view;
391
392} // namespace sourcemeta::core
393
394#endif
std::string_view rel
The link relation type.
Definition http.h:191
bool secure
Whether the cookie is only sent over secure channels.
Definition http.h:296
std::optional< std::chrono::seconds > max_age
The cookie lifetime.
Definition http.h:292
bool http_only
Whether the cookie is withheld from scripts.
Definition http.h:294
std::optional< std::string_view > domain
The host the cookie is scoped to.
Definition http.h:290
std::string_view name
The cookie name.
Definition http.h:284
std::span< const std::pair< std::string_view, std::string_view > > parameters
The additional target attributes of the link.
Definition http.h:193
std::optional< HTTPCookieSameSite > same_site
The cross-site request policy for the cookie.
Definition http.h:298
std::optional< std::string_view > path
The path the cookie is scoped to.
Definition http.h:288
std::string_view target
The link target reference.
Definition http.h:189
std::string_view value
The cookie value.
Definition http.h:286
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_from_date(const std::string_view value) noexcept -> std::optional< std::chrono::system_clock::time_point >
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:267
SOURCEMETA_CORE_HTTP_EXPORT auto http_parse_bearer(const std::string_view authorization) noexcept -> std::string_view
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
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_format_links(std::span< const HTTPLink > links, std::string &out) -> void
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_format_link(const HTTPLink &link, std::string &out) -> void
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
HTTPContentEncoding
Definition http.h:42
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:269
@ None
The cookie is sent on every cross-site request.
Definition http.h:273
@ Lax
The cookie is sent on top-level cross-site navigations only.
Definition http.h:271
@ Identity
The identity coding that applies no transformation.
Definition http.h:44
@ GZIP
The gzip coding per RFC 9110 ยง8.4.1.3.
Definition http.h:46
Definition http.h:282