Repository navigation
Add opt-in reusable application lifecycles #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
092f7ec
feat: add opt-in reusable application lifecycles
prk-Jr aed7b98
fix: import dispatch types for WASM Clippy
prk-Jr 57ac5bb
test: preserve lifecycle smoke failure diagnostics
prk-Jr 277544c
Complete custom lifecycle contract and scope config validation
prk-Jr 76c59b4
Add reusable lifecycle helpers for custom Fastly dispatch
prk-Jr d0e13d2
Cover Cloudflare response headers and clarify lifecycle contracts
prk-Jr c4841b6
Fix Cloudflare contract test import for WASM Clippy
prk-Jr 3fa334e
Merge branch 'main' into feat/reusable-app-lifecycle
prk-Jr 1aaa19a
fix: match selected adapter case-insensitively in config validation
prk-Jr 69d3784
fix: address reusable app lifecycle review findings
prk-Jr 35a7283
Merge main and reconcile lifecycle documentation
prk-Jr 9a66977
fix: address follow-up lifecycle review findings
prk-Jr 90ac41d
fix: tighten follow-up review fixes after self-review
prk-Jr 1f07d20
docs: polish lifecycle review fixes after re-review
prk-Jr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
crates/edgezero-adapter-cloudflare/src/response_headers.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| use edgezero_core::http::HeaderMap; | ||
|
|
||
| /// Replace a body-generated default with the first valid application value, | ||
| /// then append additional values. Non-text values retain the adapter's skip policy. | ||
| pub(crate) fn copy_headers<E, F>(headers: &HeaderMap, mut write: F) -> Result<(), E> | ||
|
prk-Jr marked this conversation as resolved.
prk-Jr marked this conversation as resolved.
|
||
| where | ||
| F: FnMut(&str, &str, bool) -> Result<(), E>, | ||
| { | ||
| for name in headers.keys() { | ||
| let mut replace = true; | ||
| for value in headers.get_all(name) { | ||
| if let Ok(text) = value.to_str() { | ||
| write(name.as_str(), text, replace)?; | ||
| replace = false; | ||
| } | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::copy_headers; | ||
| use edgezero_core::http::{HeaderMap, HeaderName, HeaderValue}; | ||
|
|
||
| #[test] | ||
| fn replaces_defaults_and_preserves_separate_cookies() { | ||
| let mut source = HeaderMap::new(); | ||
| source.append("set-cookie", HeaderValue::from_static("first=1; Path=/")); | ||
| source.append("set-cookie", HeaderValue::from_static("second=2; Path=/")); | ||
| source.insert("content-type", HeaderValue::from_static("text/plain")); | ||
| let mut target = HeaderMap::new(); | ||
| target.insert( | ||
| "content-type", | ||
| HeaderValue::from_static("application/octet-stream"), | ||
| ); | ||
| target.insert("set-cookie", HeaderValue::from_static("default=discard")); | ||
| copy_headers(&source, |name, value, replace| { | ||
| let parsed_name = name.parse::<HeaderName>().unwrap(); | ||
| let parsed_value = HeaderValue::from_str(value).unwrap(); | ||
| if replace { | ||
| target.insert(parsed_name, parsed_value); | ||
| } else { | ||
| target.append(parsed_name, parsed_value); | ||
| } | ||
| Ok::<_, ()>(()) | ||
| }) | ||
| .unwrap(); | ||
| assert_eq!(target, source); | ||
| assert_eq!(target.get_all("set-cookie").iter().count(), 2); | ||
| } | ||
|
|
||
| #[test] | ||
| fn first_valid_value_replaces_even_after_invalid_value() { | ||
| let mut source = HeaderMap::new(); | ||
| source.append("x-test", HeaderValue::from_bytes(b"\xff").unwrap()); | ||
| source.append("x-test", HeaderValue::from_static("valid")); | ||
| source.append("x-test", HeaderValue::from_static("next")); | ||
| let mut writes = Vec::new(); | ||
| copy_headers(&source, |_, value, replace| { | ||
| writes.push((value.to_owned(), replace)); | ||
| Ok::<_, ()>(()) | ||
| }) | ||
| .unwrap(); | ||
| assert_eq!( | ||
| writes, | ||
| [("valid".to_owned(), true), ("next".to_owned(), false)] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn invalid_only_values_do_not_touch_generated_defaults() { | ||
| let mut source = HeaderMap::new(); | ||
| source.append("x-test", HeaderValue::from_bytes(b"\xff").unwrap()); | ||
| copy_headers(&source, |_, _, _| -> Result<(), ()> { | ||
| panic!("invalid text must not reach the sink") | ||
| }) | ||
| .unwrap(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn stops_at_sink_error() { | ||
| let mut source = HeaderMap::new(); | ||
| source.append("set-cookie", HeaderValue::from_static("first=1")); | ||
| source.append("set-cookie", HeaderValue::from_static("second=2")); | ||
| let mut calls = 0_u32; | ||
| let result = copy_headers(&source, |_, _, _| { | ||
| calls += 1; | ||
| Err("header rejected") | ||
| }); | ||
| assert_eq!(result, Err("header rejected")); | ||
| assert_eq!(calls, 1); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.