Fastly Compute C++ SDK
Loading...
Searching...
No Matches
esi.cpp
#include "fastly/sdk.h"
int main() {
fastly::log::init_simple("logs", fastly::log::LogLevelFilter::Debug);
auto bereq = fastly::http::Request(fastly::http::Method::GET,
"https://esi-cpp-demo.edgecompute.app/")
auto beresp = bereq.clone_without_body().send("esi-cpp-demo").value();
// Pass in the request made to the backend as a template for fragment
// requests: this ensures that the fragment requests also ask for gzipped
// content and automatically gunzip the response content.
fastly::esi::Processor processor(std::move(bereq));
auto dispatch_fragment_request = [](fastly::http::Request req)
-> std::optional<fastly::esi::PendingFragmentContent> {
auto pending = req.send_async("esi-cpp-demo");
if (pending) {
return fastly::esi::PendingFragmentContent{std::move(*pending)};
} else {
return std::nullopt;
}
};
auto result = processor.process_response(
beresp, std::nullopt, dispatch_fragment_request, std::nullopt);
if (!result) {
fastly::log::error("Failed to process response");
}
}
int main()
Definition async_reqs.cpp:10
Definition esi.h:78
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
static Request from_client()
fastly::expected< Response > send(fastly::backend::Backend &backend)
Request clone_without_body()
Request with_auto_decompress_gzip(bool gzip) &&
std::variant< http::request::PendingRequest, http::Response, std::monostate > PendingFragmentContent
Definition esi.h:39
void init_simple(Endpoint endpoint, LogLevelFilter level)
void error(std::format_string< Args... > fmt, Args &&...args)
Definition log.h:210