Repository navigation
Preserve outbound cache tags and borrowed readiness #460
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
Changes from all commits
251974d
dc29607
683d558
cec1988
c191a9c
dd21af8
03d192f
1568f68
ce94fe0
5ca954c
e8e1d9c
e93f7e5
d914d22
cdd7c56
90a1d4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ on: | |
| push: | ||
| branches: ["main"] | ||
| pull_request: | ||
| branches: ["main"] | ||
| schedule: | ||
| - cron: "40 17 * * 3" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ on: | |
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ on: | |
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ use edgezero_core::error::{BadGatewayReason, BudgetSource}; | |
| all(feature = "cloudflare", target_arch = "wasm32"), | ||
| feature = "test-utils" | ||
| ))] | ||
| use edgezero_core::outbound::OutboundRequest; | ||
| use edgezero_core::outbound::{OutboundCachePolicy, OutboundRequest}; | ||
| #[cfg(feature = "test-utils")] | ||
| use edgezero_core::outbound::{OutboundSendMode, validate_for_dispatch}; | ||
|
|
||
|
|
@@ -341,7 +341,8 @@ mod worker_impl { | |
| let worker_body = | ||
| request_body(body, max_request_body_bytes, budget, time.clone()).await?; | ||
| let url = uri.to_string(); | ||
| let request = build_worker_request(&method, &url, &headers, worker_body, cache_policy)?; | ||
| let request = | ||
| build_worker_request(&method, &url, &headers, worker_body, &cache_policy)?; | ||
| let (response, abort_guard) = raw_fetch( | ||
| request, | ||
| budget, | ||
|
|
@@ -581,13 +582,13 @@ mod worker_impl { | |
| url: &str, | ||
| headers: &HeaderMap, | ||
| request_body: Option<JsValue>, | ||
| cache_policy: OutboundCachePolicy, | ||
| cache_policy: &OutboundCachePolicy, | ||
| ) -> Result<WorkerRequest, EdgeError> { | ||
| let mut init = RequestInit::new(); | ||
| init.with_headers(build_headers(headers)?) | ||
| .with_method(worker_method(method)) | ||
| .with_redirect(RequestRedirect::Manual); | ||
| if cache_policy == OutboundCachePolicy::Bypass { | ||
| if matches!(cache_policy, OutboundCachePolicy::Bypass) { | ||
| init.with_cache(CacheMode::NoStore); | ||
| } | ||
| if let Some(worker_body) = request_body { | ||
|
|
@@ -1899,6 +1900,65 @@ mod worker_impl { | |
| assert!(results.slots().iter().all(|slot| matches!(slot, OutboundCollectedSlot::Resolved(result) if result.outcome.is_ok()))); | ||
| } | ||
|
|
||
| #[wasm_bindgen_test] | ||
| async fn tagged_default_is_rejected_before_body_poll_or_fetch() { | ||
| let _timers = NumericTimeoutGuard::install(); | ||
| let (probe, _restore) = fetch_probe(false); | ||
| let client = HttpClient::with_client(CloudflareOutboundClient::new()); | ||
| let polls = Rc::new(Cell::new(0_usize)); | ||
| let tagged = || { | ||
| OutboundRequest::get("https://fixture.invalid/tagged") | ||
| .expect("request") | ||
| .cache_policy(OutboundCachePolicy::PlatformDefaultWithSurrogateKey( | ||
| HeaderValue::from_static("example-all"), | ||
| )) | ||
| }; | ||
| let streamed = || { | ||
| let observed = Rc::clone(&polls); | ||
| tagged().body(Body::from_stream(stream::poll_fn(move |_cx| { | ||
| observed.set(observed.get().saturating_add(1)); | ||
| Poll::Ready(None) | ||
| }))) | ||
| }; | ||
| let check = |error: &EdgeError| { | ||
| assert_eq!(error.status(), StatusCode::BAD_REQUEST); | ||
| assert!(error.message().contains("surrogate keys")); | ||
| assert!(error.message().contains("cloudflare")); | ||
| }; | ||
|
|
||
| check(&client.send(streamed()).await.expect_err("tagged send")); | ||
| check(&client.begin(streamed()).await.expect_err("tagged begin")); | ||
| let results = client | ||
| .send_all_until( | ||
| vec![ | ||
| tagged(), | ||
| OutboundRequest::get("https://fixture.invalid/untagged").expect("request"), | ||
| ], | ||
| Deadline::after(Duration::from_secs(1)), | ||
| ) | ||
| .await | ||
| .expect("batch outcomes"); | ||
| check( | ||
| resolved_slot(&results.slots()[0]) | ||
| .outcome | ||
| .as_ref() | ||
| .expect_err("tagged batch slot"), | ||
| ); | ||
| let untagged = resolved_slot(&results.slots()[1]) | ||
| .outcome | ||
| .as_ref() | ||
| .expect("untagged batch slot"); | ||
| assert_eq!(untagged.status(), StatusCode::OK); | ||
| assert_eq!(polls.get(), 0); | ||
| assert_eq!( | ||
| Reflect::get(&probe, &JsValue::from_str("calls")) | ||
| .expect("calls") | ||
| .as_f64(), | ||
| Some(1.0_f64), | ||
| "only the untagged batch slot should fetch" | ||
| ); | ||
| } | ||
|
|
||
| #[wasm_bindgen_test] | ||
| async fn begin_dispatches_without_collection_and_drop_aborts() { | ||
| let _timers = NumericTimeoutGuard::install(); | ||
|
|
@@ -2231,6 +2291,33 @@ mod worker_impl { | |
| assert_eq!(before.body().as_bytes(), after.body().as_bytes()); | ||
| } | ||
|
|
||
| #[wasm_bindgen_test] | ||
| fn untagged_cache_policies_keep_worker_default_and_no_store_modes() { | ||
| for (policy, expected) in [ | ||
| (OutboundCachePolicy::PlatformDefault, "default"), | ||
| (OutboundCachePolicy::Bypass, "no-store"), | ||
| ] { | ||
| let request = build_worker_request( | ||
| &Method::GET, | ||
| "https://origin.example.com/resource", | ||
| &HeaderMap::new(), | ||
| None, | ||
| &policy, | ||
| ) | ||
| .expect("Workers request"); | ||
| let mode = Reflect::get(request.inner().as_ref(), &JsValue::from_str("cache")) | ||
| .expect("cache mode"); | ||
| assert_eq!(mode.as_string().as_deref(), Some(expected)); | ||
| assert!( | ||
| request | ||
| .headers() | ||
| .get("surrogate-key") | ||
| .expect("header") | ||
| .is_none() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[wasm_bindgen_test] | ||
| fn provider_diagnostics_preserve_preparation_errors_without_changing_sources() { | ||
| let mut headers = HeaderMap::new(); | ||
|
|
@@ -2262,7 +2349,7 @@ mod worker_impl { | |
| "https://example.com/?token=provider-secret-token", | ||
| &HeaderMap::new(), | ||
| Some(JsValue::from_str("body")), | ||
| OutboundCachePolicy::PlatformDefault, | ||
| &OutboundCachePolicy::PlatformDefault, | ||
| ) | ||
| .expect_err("GET body rejection"); | ||
| assert_eq!( | ||
|
|
@@ -2358,7 +2445,7 @@ mod worker_impl { | |
| "https://example.com/?token=provider-secret-token", | ||
| &HeaderMap::new(), | ||
| None, | ||
| OutboundCachePolicy::PlatformDefault, | ||
| &OutboundCachePolicy::PlatformDefault, | ||
| ) | ||
| .expect("valid request"); | ||
| let start = MonotonicInstant::now(); | ||
|
|
@@ -3807,6 +3894,14 @@ fn validate_supported_options(request: &OutboundRequest) -> Result<(), EdgeError | |
| "image_optimizer is not supported by cloudflare", | ||
| )); | ||
| } | ||
| if matches!( | ||
| request.cache_policy_setting(), | ||
| OutboundCachePolicy::PlatformDefaultWithSurrogateKey(_) | ||
| ) { | ||
| return Err(EdgeError::bad_request( | ||
| "outbound cache surrogate keys are not supported by cloudflare", | ||
| )); | ||
| } | ||
|
Comment on lines
+3897
to
+3904
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😃 This follows the existing Image Optimizer rejection, and |
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -3845,6 +3940,22 @@ mod header_bridge_tests { | |
|
|
||
| use super::*; | ||
|
|
||
| #[cfg(feature = "test-utils")] | ||
| #[test] | ||
| fn tagged_default_is_unsupported_in_batch_preflight() { | ||
| let request = OutboundRequest::get("https://origin.example.com/resource") | ||
| .expect("request") | ||
| .cache_policy( | ||
| edgezero_core::OutboundCachePolicy::PlatformDefaultWithSurrogateKey( | ||
| HeaderValue::from_static("example-all"), | ||
| ), | ||
| ); | ||
| let error = validate_batch_request_for_test(&request).expect_err("tagged request"); | ||
| assert!(matches!(error, EdgeError::BadRequest { .. })); | ||
| assert!(error.message().contains("surrogate keys")); | ||
| assert!(error.message().contains("cloudflare")); | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| struct AppendSink(BTreeMap<String, Vec<String>>); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.