workers-rs
workers-rs copied to clipboard
Serialize cache_ttl_by_status as object in cf properties
Fixes #442
Serializes ttl_status_map as an object instead of a JavaScript Map using a serde_wasm_bindgen serializer.
Inspecting cf properties, TTL attributes are now present.
Before:
request cf properties: Cf { inner: IncomingRequestCfProperties { obj: Object { obj: JsValue(Object({"apps":true,"cacheEverything":true,"cacheKey":"","cacheTtl":0,"cacheTtlByStatus":{},"minify":{"__wbg_ptr":1455240},"mirage":true,"polish":"off","resolveOverride":"","scrapeShield":true})) } } }
After
request cf properties: Cf { inner: IncomingRequestCfProperties { obj: Object { obj: JsValue(Object({"apps":true,"cacheEverything":true,"cacheKey":"","cacheTtl":0,"cacheTtlByStatus":{"200-299":5,"300-399":10},"minify":{"__wbg_ptr":1311768},"mirage":true,"polish":"off","resolveOverride":"","scrapeShield":true})) } } }
Repeating the test from the reported issue:
const originResponse = await fetch(url, {
cf: {
cacheEverything: true,
cacheTtlByStatus: {
'200-299': 5,
'300-399': 10,
},
}
});
The behavior now matches that of the JavaScript implementation:
172.69.64.52 - - [14/Feb/2024:04:55:56 +0000] "GET / HTTP/1.1" 304"
172.69.64.52 - - [14/Feb/2024:04:56:07 +0000] "GET / HTTP/1.1" 304"
172.69.64.52 - - [14/Feb/2024:04:56:18 +0000] "GET / HTTP/1.1" 304"
172.69.64.52 - - [14/Feb/2024:04:56:29 +0000] "GET / HTTP/1.1" 304"
172.69.64.52 - - [14/Feb/2024:04:56:40 +0000] "GET / HTTP/1.1" 304"
This test is broken on main, I'm looking into it
I think I've fixed the test in #445 , once I land that we can rebase.
@caiges Could you rebase?
@kflansburg :heavy_check_mark: