ESI for Fastly
This crate provides a streaming Edge Side Includes parser and executor designed for Fastly Compute@Edge.
The implementation is currently a subset of the ESI Language Specification 1.0, so
only the esi:include
tag is supported. Other tags will be ignored.
Usage Example
use esi::Processor;
use fastly::{http::StatusCode, mime, Error, Request, Response};
fn main() {
if let Err(err) = handle_request(Request::from_client()) {
println!("returning error response");
Response::from_status(StatusCode::INTERNAL_SERVER_ERROR)
.with_body(err.to_string())
.send_to_client();
}
}
fn handle_request(req: Request) -> Result<(), Error> {
let beresp = req.clone_without_body().send("origin_0")?;
let config = esi::Configuration::default();
let processor = Processor::new(config);
processor.execute_esi(req, beresp, &|req| {
Ok(req.with_ttl(120).send("origin_1")?)
})?;
Ok(())
}