diff --git a/src/workerd/api/tests/cf-cache-control-test.js b/src/workerd/api/tests/cf-cache-control-test.js index 0b71367b9d9..d2df14441d8 100644 --- a/src/workerd/api/tests/cf-cache-control-test.js +++ b/src/workerd/api/tests/cf-cache-control-test.js @@ -139,6 +139,7 @@ export const additionalCacheSettings = { stripLastModified: false, cacheDeceptionArmor: true, cacheReserveMinimumFileSize: 1024, + originRangeRequests: 'off', vary: { default: { action: 'bypass' }, headers: { @@ -158,6 +159,7 @@ export const additionalCacheSettings = { assert.strictEqual(req.cf.stripLastModified, false); assert.strictEqual(req.cf.cacheDeceptionArmor, true); assert.strictEqual(req.cf.cacheReserveMinimumFileSize, 1024); + assert.strictEqual(req.cf.originRangeRequests, 'off'); assert.deepStrictEqual(req.cf.vary, { default: { action: 'bypass' }, headers: { diff --git a/types/defines/cf.d.ts b/types/defines/cf.d.ts index cbfbf3ba2c2..df79e20cf4d 100644 --- a/types/defines/cf.d.ts +++ b/types/defines/cf.d.ts @@ -36,6 +36,14 @@ interface RequestInitCfProperties extends Record { * (e.g. { '200-299': 86400, '404': 1, '500-599': 0 }) */ cacheTtlByStatus?: Record; + /** + * Controls whether Cloudflare uses range requests when fetching the response + * from the origin. + * + * - `"on"`: enable origin range requests for this request. + * - `"off"`: disable origin range requests for this request. + */ + originRangeRequests?: "on" | "off"; /** Controls how responses with a `Vary` header are cached for this request. */ vary?: RequestInitCfPropertiesVary; /** diff --git a/types/test/types/cf.ts b/types/test/types/cf.ts index 53a12120190..a84dde2e98d 100644 --- a/types/test/types/cf.ts +++ b/types/test/types/cf.ts @@ -22,6 +22,21 @@ export const handler: ExportedHandler<{ SERVICE: Fetcher }> = { cf: { cacheEverything: true }, }); + await fetch("https://example.com", { + cf: { originRangeRequests: "on" }, + }); + + await fetch("https://example.com", { + cf: { originRangeRequests: "off" }, + }); + + await fetch("https://example.com", { + cf: { + // @ts-expect-error: default is a Cache Rules value, not a Workers value + originRangeRequests: "default", + }, + }); + await fetch("https://example.com", { cf: { vary: {