Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/workerd/api/tests/cf-cache-control-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const additionalCacheSettings = {
stripLastModified: false,
cacheDeceptionArmor: true,
cacheReserveMinimumFileSize: 1024,
originRangeRequests: 'off',
vary: {
default: { action: 'bypass' },
headers: {
Expand All @@ -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: {
Expand Down
8 changes: 8 additions & 0 deletions types/defines/cf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ interface RequestInitCfProperties extends Record<string, unknown> {
* (e.g. { '200-299': 86400, '404': 1, '500-599': 0 })
*/
cacheTtlByStatus?: Record<string, number>;
/**
* 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;
/**
Expand Down
15 changes: 15 additions & 0 deletions types/test/types/cf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading