Fastly Compute C++ SDK
Loading...
Searching...
No Matches
esi.h
Go to the documentation of this file.
1#ifndef FASTLY_ESI_H
2#define FASTLY_ESI_H
3
4#include <concepts>
6#include <fastly/error.h>
7#include <fastly/expected.h>
10#include <fastly/sdk-sys.h>
11#include <functional>
12#include <optional>
13#include <string>
14#include <utility>
15#include <variant>
16
17namespace fastly::esi {
20public:
24 Configuration(std::string namespc = "esi", bool is_escaped_content = true)
25 : namespace_(std::move(namespc)),
26 is_escaped_content_(is_escaped_content) {}
27
28 std::string_view get_namespace() const { return namespace_; }
29 bool is_escaped_content() const { return is_escaped_content_; }
30
31private:
32 std::string namespace_;
33 bool is_escaped_content_;
34};
35
40 std::variant<http::request::PendingRequest, http::Response, std::monostate>;
41
45public:
48 std::function<std::optional<PendingFragmentContent>(Request)>;
49
50 template <std::convertible_to<function_type> F>
51 DispatchFragmentRequestFn(F &&fn) : fn_(std::forward<F>(fn)) {}
52
53private:
55 auto &inner() const { return fn_; }
56 function_type fn_;
57};
58
62public:
65 std::function<std::optional<Response>(Request &, Response)>;
66
67 template <std::convertible_to<function_type> F>
68 ProcessFragmentResponseFn(F &&fn) : fn_(std::forward<F>(fn)) {}
69
70private:
72 auto &inner() const { return fn_; }
73 function_type fn_;
74};
75
78class Processor {
79public:
81 Processor(std::optional<Request> original_request_metadata = std::nullopt,
82 Configuration config = Configuration());
83
96 Response &src_document,
97 std::optional<Response> client_response_metadata = std::nullopt,
98 std::optional<DispatchFragmentRequestFn> dispatch_fragment_request =
99 std::nullopt,
100 std::optional<ProcessFragmentResponseFn> process_fragment_response =
101 std::nullopt);
102
112 const std::string &src_document,
113 std::optional<DispatchFragmentRequestFn> dispatch_fragment_request =
114 std::nullopt,
115 std::optional<ProcessFragmentResponseFn> process_fragment_response =
116 std::nullopt);
117
118private:
119 rust::Box<fastly::sys::esi::Processor> processor_;
120};
121
122} // namespace fastly::esi
123#endif
DispatchFragmentRequestFn(F &&fn)
Definition esi.h:51
std::function< std::optional< PendingFragmentContent >(Request)> function_type
The type of the dispatch function.
Definition esi.h:47
ProcessFragmentResponseFn(F &&fn)
Definition esi.h:68
std::function< std::optional< Response >(Request &, Response)> function_type
The type of the processing function.
Definition esi.h:64
Processor(std::optional< Request > original_request_metadata=std::nullopt, Configuration config=Configuration())
Create a new ESI processor with the given configuration.
fastly::expected< std::string > process_document(const std::string &src_document, std::optional< DispatchFragmentRequestFn > dispatch_fragment_request=std::nullopt, std::optional< ProcessFragmentResponseFn > process_fragment_response=std::nullopt)
fastly::expected< void > process_response(Response &src_document, std::optional< Response > client_response_metadata=std::nullopt, std::optional< DispatchFragmentRequestFn > dispatch_fragment_request=std::nullopt, std::optional< ProcessFragmentResponseFn > process_fragment_response=std::nullopt)
Definition request.h:149
Definition response.h:94
tl::expected< T, FastlyError > expected
Definition error.h:25
Definition esi.h:17
std::variant< http::request::PendingRequest, http::Response, std::monostate > PendingFragmentContent
Definition esi.h:39
Definition access_bridge_internals.h:11
Used to configure optional behaviour within the ESI processor.
Definition esi.h:19
bool is_escaped_content() const
Definition esi.h:29
std::string_view get_namespace() const
Definition esi.h:28
Configuration(std::string namespc="esi", bool is_escaped_content=true)
Definition esi.h:24