From 3c2d98aad4a31151a0c8b375b2d6e79b9b125714 Mon Sep 17 00:00:00 2001 From: Kailan Blanks Date: Tue, 9 Jul 2024 14:15:49 +0100 Subject: [PATCH 1/4] Bump `fastly` and crate versions --- esi/Cargo.toml | 4 ++-- examples/esi_example_advanced_error_handling/Cargo.toml | 6 +++--- examples/esi_example_minimal/Cargo.toml | 6 +++--- examples/esi_example_minimal/fastly.toml | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/esi/Cargo.toml b/esi/Cargo.toml index b9c5d4d..73817de 100644 --- a/esi/Cargo.toml +++ b/esi/Cargo.toml @@ -11,8 +11,8 @@ readme = "./README.md" [dependencies] quick-xml = "0.27.1" 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" diff --git a/examples/esi_example_advanced_error_handling/Cargo.toml b/examples/esi_example_advanced_error_handling/Cargo.toml index 7287210..7254c1c 100644 --- a/examples/esi_example_advanced_error_handling/Cargo.toml +++ b/examples/esi_example_advanced_error_handling/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "esi_example_advanced_error_handling" -version = "0.4.0" +version = "0.4.1" authors = ["Kailan Blanks "] edition = "2018" publish = false [dependencies] -fastly = "^0.9" +fastly = "^0.10" esi = { path = "../../esi" } quick-xml = "0.27.1" log = "^0.4" -env_logger = "=0.9.3" # 0.10.0 requires nightly +env_logger = "^0.11" # 0.10.0 requires nightly diff --git a/examples/esi_example_minimal/Cargo.toml b/examples/esi_example_minimal/Cargo.toml index 9b9c5bc..b05bbc6 100644 --- a/examples/esi_example_minimal/Cargo.toml +++ b/examples/esi_example_minimal/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "esi_example_minimal" -version = "0.4.0" +version = "0.4.1" authors = ["Kailan Blanks "] edition = "2018" 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" diff --git a/examples/esi_example_minimal/fastly.toml b/examples/esi_example_minimal/fastly.toml index 49d68f3..01d2f07 100644 --- a/examples/esi_example_minimal/fastly.toml +++ b/examples/esi_example_minimal/fastly.toml @@ -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" From 420d8bce73a141c15d644e54b63e1591eb231edf Mon Sep 17 00:00:00 2001 From: Kailan Blanks Date: Tue, 9 Jul 2024 14:20:07 +0100 Subject: [PATCH 2/4] Update `quick_xml` --- esi/Cargo.toml | 2 +- esi/src/lib.rs | 10 +++++----- .../esi_example_advanced_error_handling/Cargo.toml | 2 +- .../src/main.rs | 14 ++++++++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/esi/Cargo.toml b/esi/Cargo.toml index 73817de..ce62a1f 100644 --- a/esi/Cargo.toml +++ b/esi/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" readme = "./README.md" [dependencies] -quick-xml = "0.27.1" +quick-xml = "0.36.0" thiserror = "^1.0" fastly = "^0.10" log = "^0.4" diff --git a/esi/src/lib.rs b/esi/src/lib.rs index 9cedcab..6800964 100644 --- a/esi/src/lib.rs +++ b/esi/src/lib.rs @@ -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 { @@ -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() { @@ -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"); } @@ -331,7 +331,7 @@ fn reader_from_body(body: Body) -> Reader { let mut reader = Reader::from_reader(body); // TODO: make this configurable - reader.check_end_names(false); + reader.config_mut().check_end_names = false; reader } diff --git a/examples/esi_example_advanced_error_handling/Cargo.toml b/examples/esi_example_advanced_error_handling/Cargo.toml index 7254c1c..6e199ed 100644 --- a/examples/esi_example_advanced_error_handling/Cargo.toml +++ b/examples/esi_example_advanced_error_handling/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies] fastly = "^0.10" esi = { path = "../../esi" } -quick-xml = "0.27.1" +quick-xml = "0.36.0" log = "^0.4" env_logger = "^0.11" # 0.10.0 requires nightly diff --git a/examples/esi_example_advanced_error_handling/src/main.rs b/examples/esi_example_advanced_error_handling/src/main.rs index bb9dde9..352290d 100644 --- a/examples/esi_example_advanced_error_handling/src/main.rs +++ b/examples/esi_example_advanced_error_handling/src/main.rs @@ -1,3 +1,5 @@ +use std::io::Write; + use fastly::{http::StatusCode, mime, Request, Response}; use log::{error, info}; use quick_xml::{Reader, Writer}; @@ -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| { @@ -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"); }); From 4a9e6794f06f923b901919e068138e5d74a850be Mon Sep 17 00:00:00 2001 From: Kailan Blanks Date: Tue, 9 Jul 2024 14:21:58 +0100 Subject: [PATCH 3/4] DRY up package metadata --- Cargo.toml | 6 ++++++ esi/Cargo.toml | 8 ++++---- examples/esi_example_advanced_error_handling/Cargo.toml | 7 ++++--- examples/esi_example_minimal/Cargo.toml | 7 ++++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ae71b03..f53b201 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,9 @@ members = [ "examples/esi_example_minimal", "examples/esi_example_advanced_error_handling" ] + +[workspace.package] +version = "4.1.0" +authors = ["Kailan Blanks "] +license = "MIT" +edition = "2018" diff --git a/esi/Cargo.toml b/esi/Cargo.toml index ce62a1f..9857afe 100644 --- a/esi/Cargo.toml +++ b/esi/Cargo.toml @@ -1,11 +1,11 @@ [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 "] -edition = "2018" readme = "./README.md" [dependencies] diff --git a/examples/esi_example_advanced_error_handling/Cargo.toml b/examples/esi_example_advanced_error_handling/Cargo.toml index 6e199ed..8b0ca11 100644 --- a/examples/esi_example_advanced_error_handling/Cargo.toml +++ b/examples/esi_example_advanced_error_handling/Cargo.toml @@ -1,8 +1,9 @@ [package] name = "esi_example_advanced_error_handling" -version = "0.4.1" -authors = ["Kailan Blanks "] -edition = "2018" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true publish = false [dependencies] diff --git a/examples/esi_example_minimal/Cargo.toml b/examples/esi_example_minimal/Cargo.toml index b05bbc6..54197f8 100644 --- a/examples/esi_example_minimal/Cargo.toml +++ b/examples/esi_example_minimal/Cargo.toml @@ -1,8 +1,9 @@ [package] name = "esi_example_minimal" -version = "0.4.1" -authors = ["Kailan Blanks "] -edition = "2018" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true publish = false [dependencies] From 33636d38bbb4ae5cbc87cb8cb5f892b0d7fab779 Mon Sep 17 00:00:00 2001 From: Kailan Blanks Date: Tue, 9 Jul 2024 14:25:52 +0100 Subject: [PATCH 4/4] elide lifetime in `parse_include` --- esi/src/parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esi/src/parse.rs b/esi/src/parse.rs index e954a13..1cefaef 100644 --- a/esi/src/parse.rs +++ b/esi/src/parse.rs @@ -106,7 +106,7 @@ where Ok(()) } -fn parse_include<'a, 'b>(elem: &'a BytesStart) -> Result> { +fn parse_include<'a>(elem: &BytesStart) -> Result> { let src = match elem .attributes() .flatten()