-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathesi.cpp
More file actions
32 lines (28 loc) · 1.2 KB
/
esi.cpp
File metadata and controls
32 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//! @example esi.cpp
#include "fastly/sdk.h"
int main() {
fastly::log::init_simple("logs", fastly::log::LogLevelFilter::Debug);
auto req{fastly::http::Request::from_client()};
auto bereq = fastly::http::Request(fastly::http::Method::GET,
"https://esi-cpp-demo.edgecompute.app/")
.with_auto_decompress_gzip(true);
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");
}
}