Socket
Socket
Sign inDemoInstall

@miniflare/cache

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miniflare/cache - npm Package Compare versions

Comparing version 2.11.0 to 2.12.0

5

dist/src/index.d.ts
import { Clock } from '@miniflare/shared';
import { Headers } from 'undici';
import { Log } from '@miniflare/shared';

@@ -65,4 +64,2 @@ import { MiniflareError } from '@miniflare/shared';

/* Excluded from this release type: _getRangeResponse */
export declare interface InternalCacheOptions {

@@ -80,4 +77,2 @@ formDataFiles?: boolean;

/* Excluded from this release type: _parseRanges */
export { }

127

dist/src/index.js

@@ -40,5 +40,3 @@ var __create = Object.create;

CacheStorage: () => CacheStorage,
NoOpCache: () => NoOpCache,
_getRangeResponse: () => _getRangeResponse,
_parseRanges: () => _parseRanges
NoOpCache: () => NoOpCache
});

@@ -48,3 +46,3 @@

var import_url = __toModule(require("url"));
var import_core2 = __toModule(require("@miniflare/core"));
var import_core = __toModule(require("@miniflare/core"));
var import_shared2 = __toModule(require("@miniflare/shared"));

@@ -59,104 +57,5 @@ var import_http_cache_semantics = __toModule(require("http-cache-semantics"));

// packages/cache/src/range.ts
var import_web = __toModule(require("stream/web"));
var import_util = __toModule(require("util"));
var import_core = __toModule(require("@miniflare/core"));
var encoder = new import_util.TextEncoder();
var rangePrefixRegexp = /^ *bytes *=/i;
var rangeRegexp = /^ *(?<start>\d+)? *- *(?<end>\d+)? *$/;
function _parseRanges(rangeHeader, length) {
const prefixMatch = rangePrefixRegexp.exec(rangeHeader);
if (prefixMatch === null)
return;
rangeHeader = rangeHeader.substring(prefixMatch[0].length);
if (rangeHeader.trimStart() === "")
return [];
const ranges = rangeHeader.split(",");
const result = [];
for (const range of ranges) {
const match = rangeRegexp.exec(range);
if (match === null)
return;
const { start, end } = match.groups;
if (start !== void 0 && end !== void 0) {
const rangeStart = parseInt(start);
let rangeEnd = parseInt(end);
if (rangeStart > rangeEnd)
return;
if (rangeStart >= length)
return;
if (rangeEnd >= length)
rangeEnd = length - 1;
result.push([rangeStart, rangeEnd]);
} else if (start !== void 0 && end === void 0) {
const rangeStart = parseInt(start);
if (rangeStart >= length)
return;
result.push([rangeStart, length - 1]);
} else if (start === void 0 && end !== void 0) {
const suffix = parseInt(end);
if (suffix >= length)
return [];
if (suffix === 0)
continue;
result.push([length - suffix, length - 1]);
} else {
return;
}
}
return result;
}
function _getRangeResponse(requestRangeHeader, responseStatus, responseHeaders, responseBody) {
const ranges = _parseRanges(requestRangeHeader, responseBody.byteLength);
if (ranges === void 0) {
return new import_core.Response(null, {
status: 416,
headers: { "Content-Range": `bytes */${responseBody.byteLength}` }
});
} else if (ranges.length === 0) {
return new import_core.Response(responseBody, {
status: responseStatus,
headers: responseHeaders
});
} else if (ranges.length === 1) {
const [start, end] = ranges[0];
responseHeaders.set("Content-Range", `bytes ${start}-${end}/${responseBody.byteLength}`);
responseHeaders.set("Content-Length", `${end - start + 1}`);
return new import_core.Response(responseBody.slice(start, end + 1), {
status: 206,
headers: responseHeaders
});
} else {
const contentType = responseHeaders.get("Content-Type");
const boundary = "miniflare-boundary-" + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString().padStart(16, "0");
const stream = new import_web.ReadableStream({
type: "bytes",
pull(controller) {
const range = ranges.shift();
if (range === void 0) {
controller.enqueue(encoder.encode(`--${boundary}--`));
return controller.close();
}
const [start, end] = range;
const header = `--${boundary}\r
Content-Type: ${contentType}\r
Content-Range: bytes ${start}-${end}/${responseBody.byteLength}\r
\r
`;
controller.enqueue(encoder.encode(header));
controller.enqueue(responseBody.slice(start, end + 1));
controller.enqueue(encoder.encode("\r\n"));
}
});
responseHeaders.set("Content-Type", `multipart/byteranges; boundary=${boundary}`);
return new import_core.Response(stream, {
status: 206,
headers: responseHeaders
});
}
}
// packages/cache/src/cache.ts
function normaliseRequest(req) {
return req instanceof import_core2.Request || req instanceof import_undici.Request ? req : new import_core2.Request(req);
return req instanceof import_core.Request || req instanceof import_undici.Request ? req : new import_core.Request(req);
}

@@ -223,7 +122,7 @@ function normaliseHeaders(headers) {

if (reqIfNoneMatchHeader.trim() === "*") {
return new import_core2.Response(null, { status: 304, headers: resHeaders });
return new import_core.Response(null, { status: 304, headers: resHeaders });
}
for (const reqIfNoneMatch of reqIfNoneMatchHeader.split(",")) {
if (resETag === parseETag(reqIfNoneMatch)) {
return new import_core2.Response(null, { status: 304, headers: resHeaders });
return new import_core.Response(null, { status: 304, headers: resHeaders });
}

@@ -239,3 +138,3 @@ }

if (resLastModified <= reqIfModifiedSince) {
return new import_core2.Response(null, { status: 304, headers: resHeaders });
return new import_core.Response(null, { status: 304, headers: resHeaders });
}

@@ -245,5 +144,5 @@ }

if (reqRangeHeader !== null) {
return _getRangeResponse(reqRangeHeader, resStatus, resHeaders, resBody);
return (0, import_core.getRangeResponse)(reqRangeHeader, resStatus, resHeaders, resBody);
}
return new import_core2.Response(resBody, { status: resStatus, headers: resHeaders });
return new import_core.Response(resBody, { status: resStatus, headers: resHeaders });
}

@@ -271,3 +170,3 @@ var Cache = class {

req = normaliseRequest(req);
if (res instanceof import_core2.Response && res.webSocket) {
if (res instanceof import_core.Response && res.webSocket) {
throw new TypeError("Cannot cache WebSocket upgrade response.");

@@ -325,4 +224,4 @@ }

if (!this.#formDataFiles)
res = (0, import_core2.withStringFormDataFiles)(res);
return (0, import_core2.withImmutableHeaders)(res);
res = (0, import_core.withStringFormDataFiles)(res);
return (0, import_core.withImmutableHeaders)(res);
}

@@ -469,6 +368,4 @@ async delete(req, options) {

CacheStorage,
NoOpCache,
_getRangeResponse,
_parseRanges
NoOpCache
});
//# sourceMappingURL=index.js.map

12

package.json
{
"name": "@miniflare/cache",
"version": "2.11.0",
"version": "2.12.0",
"description": "Cache module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers",

@@ -38,12 +38,12 @@ "keywords": [

"dependencies": {
"@miniflare/core": "2.11.0",
"@miniflare/shared": "2.11.0",
"@miniflare/core": "2.12.0",
"@miniflare/shared": "2.12.0",
"http-cache-semantics": "^4.1.0",
"undici": "5.9.1"
"undici": "5.11.0"
},
"devDependencies": {
"@miniflare/shared-test": "2.11.0",
"@miniflare/web-sockets": "2.11.0",
"@miniflare/shared-test": "2.12.0",
"@miniflare/web-sockets": "2.12.0",
"@types/http-cache-semantics": "^4.0.1"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc