workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

Serialize cache_ttl_by_status as object in cf properties

Open caiges opened this issue 1 year ago • 2 comments

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"

caiges avatar Feb 14 '24 05:02 caiges

This test is broken on main, I'm looking into it

kflansburg avatar Feb 14 '24 15:02 kflansburg

I think I've fixed the test in #445 , once I land that we can rebase.

kflansburg avatar Feb 14 '24 17:02 kflansburg

@caiges Could you rebase?

kflansburg avatar Feb 26 '24 16:02 kflansburg

@kflansburg :heavy_check_mark:

caiges avatar Feb 26 '24 16:02 caiges