diff --git a/integration-tests/js-compute/fixtures/app/src/request-cache-key.js b/integration-tests/js-compute/fixtures/app/src/request-cache-key.js index f5e580080a..b931ad76ac 100644 --- a/integration-tests/js-compute/fixtures/app/src/request-cache-key.js +++ b/integration-tests/js-compute/fixtures/app/src/request-cache-key.js @@ -63,7 +63,6 @@ import { routes } from "./routes.js"; }); routes.set("/request/constructor/cacheKey", () => { const request = new Request('https://www.fastly.com', {cacheKey: 'meow'}) - request.setCacheKey('meow') let error = assert(request.headers.get('fastly-xqd-cache-key'), '404CDD7BC109C432F8CC2443B45BCFE95980F5107215C645236E577929AC3E52', `request.headers.get('fastly-xqd-cache-key'`) if (error) { return error } return pass() diff --git a/runtime/fastly/builtins/fetch/request-response.cpp b/runtime/fastly/builtins/fetch/request-response.cpp index 5a6018e11b..e76f305f07 100644 --- a/runtime/fastly/builtins/fetch/request-response.cpp +++ b/runtime/fastly/builtins/fetch/request-response.cpp @@ -1767,6 +1767,7 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H JS::RootedValue body_val(cx); JS::RootedValue backend_val(cx); JS::RootedValue cache_override(cx); + JS::RootedValue cache_key(cx); JS::RootedValue fastly_val(cx); JS::RootedValue manualFramingHeaders(cx); bool hasmanualFramingHeaders; @@ -1777,6 +1778,7 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H !JS_GetProperty(cx, init, "body", &body_val) || !JS_GetProperty(cx, init, "backend", &backend_val) || !JS_GetProperty(cx, init, "cacheOverride", &cache_override) || + !JS_GetProperty(cx, init, "cacheKey", &cache_key) || !JS_GetProperty(cx, init, "fastly", &fastly_val) || !JS_HasOwnProperty(cx, init, "manualFramingHeaders", &hasmanualFramingHeaders) || !JS_GetProperty(cx, init, "manualFramingHeaders", &manualFramingHeaders)) { @@ -2074,6 +2076,14 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H JS::GetReservedSlot(input_request, static_cast(Slots::CacheOverride))); } + // Apply the Fastly Compute-proprietary `cacheKey` property. + // (in the input_request case, the header will be copied across normally) + if (!cache_key.isUndefined()) { + if (!set_cache_key(cx, request, cache_key)) { + return nullptr; + } + } + if (fastly_val.isObject()) { JS::RootedValue decompress_response_val(cx); JS::RootedObject fastly(cx, fastly_val.toObjectOrNull()); diff --git a/runtime/js-compute-runtime/builtins/request-response.cpp b/runtime/js-compute-runtime/builtins/request-response.cpp index f4c4dbe261..387c3973cb 100644 --- a/runtime/js-compute-runtime/builtins/request-response.cpp +++ b/runtime/js-compute-runtime/builtins/request-response.cpp @@ -1814,6 +1814,7 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H JS::RootedValue body_val(cx); JS::RootedValue backend_val(cx); JS::RootedValue cache_override(cx); + JS::RootedValue cache_key(cx); JS::RootedValue fastly_val(cx); JS::RootedValue manualFramingHeaders(cx); bool hasmanualFramingHeaders; @@ -1824,6 +1825,7 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H !JS_GetProperty(cx, init, "body", &body_val) || !JS_GetProperty(cx, init, "backend", &backend_val) || !JS_GetProperty(cx, init, "cacheOverride", &cache_override) || + !JS_GetProperty(cx, init, "cacheKey", &cache_key) || !JS_GetProperty(cx, init, "fastly", &fastly_val) || !JS_HasOwnProperty(cx, init, "manualFramingHeaders", &hasmanualFramingHeaders) || !JS_GetProperty(cx, init, "manualFramingHeaders", &manualFramingHeaders)) { @@ -2119,6 +2121,13 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H request, static_cast(Slots::CacheOverride), JS::GetReservedSlot(input_request, static_cast(Slots::CacheOverride))); } + // Apply the Fastly Compute-proprietary `cacheKey` property. + // (in the input_request case, the header will be copied across normally) + if (!cache_key.isUndefined()) { + if (!set_cache_key(cx, request, cache_key)) { + return nullptr; + } + } if (fastly_val.isObject()) { JS::RootedValue decompress_response_val(cx);