Skip to content

Commit

Permalink
Merge pull request #26 from fastly/version-041
Browse files Browse the repository at this point in the history
Release version `0.4.1`
  • Loading branch information
kailan authored Jul 9, 2024
2 parents c7f34e7 + 33636d3 commit 93e802b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ members = [
"examples/esi_example_minimal",
"examples/esi_example_advanced_error_handling"
]

[workspace.package]
version = "4.1.0"
authors = ["Kailan Blanks <[email protected]>"]
license = "MIT"
edition = "2018"
14 changes: 7 additions & 7 deletions esi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "esi"
version = "0.4.1"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
description = "A streaming parser and executor for Edge Side Includes"
repository = "https://github.com/fastly/esi"
license = "MIT"
authors = ["Kailan Blanks <[email protected]>"]
edition = "2018"
readme = "./README.md"

[dependencies]
quick-xml = "0.27.1"
quick-xml = "0.36.0"
thiserror = "^1.0"
fastly = "^0.9"
fastly = "^0.10"
log = "^0.4"

[dev-dependencies]
env_logger = "=0.9.3" # 0.10.0 requires nightly
env_logger = "^0.11"
10 changes: 5 additions & 5 deletions esi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Processor {
debug!("nothing waiting so streaming directly to client");
output_writer.write_event(event)?;
output_writer
.inner()
.get_mut()
.flush()
.expect("failed to flush output");
} else {
Expand Down Expand Up @@ -262,7 +262,7 @@ fn poll_elements(
match element {
Element::Raw(raw) => {
debug!("writing previously queued other content");
output_writer.inner().write_all(&raw).unwrap();
output_writer.get_mut().write_all(&raw).unwrap();
}
Element::Fragment(mut request, alt, continue_on_error, pending_request) => {
match pending_request.wait() {
Expand Down Expand Up @@ -305,11 +305,11 @@ fn poll_elements(
// Response status is success,
// write the response body to the output stream.
output_writer
.inner()
.get_mut()
.write_all(&res.into_body_bytes())
.unwrap();
output_writer
.inner()
.get_mut()
.flush()
.expect("failed to flush output");
}
Expand All @@ -331,7 +331,7 @@ fn reader_from_body(body: Body) -> Reader<Body> {
let mut reader = Reader::from_reader(body);

// TODO: make this configurable
reader.check_end_names(false);
reader.config_mut().check_end_names = false;

reader
}
2 changes: 1 addition & 1 deletion esi/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
Ok(())
}

fn parse_include<'a, 'b>(elem: &'a BytesStart) -> Result<Event<'b>> {
fn parse_include<'a>(elem: &BytesStart) -> Result<Event<'a>> {
let src = match elem
.attributes()
.flatten()
Expand Down
13 changes: 7 additions & 6 deletions examples/esi_example_advanced_error_handling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "esi_example_advanced_error_handling"
version = "0.4.0"
authors = ["Kailan Blanks <[email protected]>"]
edition = "2018"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
publish = false

[dependencies]
fastly = "^0.9"
fastly = "^0.10"
esi = { path = "../../esi" }
quick-xml = "0.27.1"
quick-xml = "0.36.0"
log = "^0.4"
env_logger = "=0.9.3" # 0.10.0 requires nightly
env_logger = "^0.11" # 0.10.0 requires nightly
14 changes: 10 additions & 4 deletions examples/esi_example_advanced_error_handling/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::io::Write;

use fastly::{http::StatusCode, mime, Request, Response};
use log::{error, info};
use quick_xml::{Reader, Writer};
Expand Down Expand Up @@ -36,7 +38,8 @@ fn main() {
// Set up an XML writer to write directly to the client output stream.
let mut xml_writer = Writer::new(output_writer);

match processor.process_document(
// Process the ESI document
let result = processor.process_document(
Reader::from_reader(beresp.take_body()),
&mut xml_writer,
Some(&|req| {
Expand All @@ -51,15 +54,18 @@ fn main() {
);
Ok(resp)
}),
) {
);

match result {
Ok(()) => {
xml_writer.into_inner().finish().unwrap();
}
Err(err) => {
error!("error processing ESI document: {}", err);
xml_writer
.inner()
.write_str(include_str!("error.html.fragment"));
.get_mut()
.write_all(include_bytes!("error.html.fragment"))
.expect("failed to write error response");
xml_writer.into_inner().finish().unwrap_or_else(|_| {
error!("error flushing error response to client");
});
Expand Down
11 changes: 6 additions & 5 deletions examples/esi_example_minimal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "esi_example_minimal"
version = "0.4.0"
authors = ["Kailan Blanks <[email protected]>"]
edition = "2018"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
publish = false

[dependencies]
fastly = "^0.9"
fastly = "^0.10"
esi = { path = "../../esi" }
log = "^0.4"
env_logger = "=0.9.3" # 0.10.0 requires nightly
env_logger = "^0.11"
1 change: 1 addition & 0 deletions examples/esi_example_minimal/fastly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ service_id = ""

[local_server.backends.mock-s3]
url = "https://mock-s3.edgecompute.app"
override_host = "mock-s3.edgecompute.app"

[scripts]
build = "cargo build --bin esi_example_minimal --release --target wasm32-wasi --color always"
Expand Down

0 comments on commit 93e802b

Please sign in to comment.