Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@miniflare/http-server

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miniflare/http-server - npm Package Compare versions

Comparing version 2.5.1 to 2.6.0-d1.1

150

dist/src/index.js

@@ -47,2 +47,3 @@ var __create = Object.create;

var import_https = __toModule(require("https"));
var import_net = __toModule(require("net"));
var import_web = __toModule(require("stream/web"));

@@ -59,6 +60,8 @@ var import_url = __toModule(require("url"));

const hosts = [];
Object.values((0, import_os.networkInterfaces)()).forEach((net) => net?.forEach(({ family, address }) => {
if (!ipv4 || family === "IPv4")
hosts.push(address);
}));
Object.values((0, import_os.networkInterfaces)()).forEach((net2) => {
net2?.forEach(({ family, address }) => {
if (!ipv4 || family === "IPv4" || family === 4)
hosts.push(address);
});
});
return hosts;

@@ -72,2 +75,3 @@ }

var import_shared = __toModule(require("@miniflare/shared"));
var import_colors = __toModule(require("kleur/colors"));
var import_undici = __toModule(require("undici"));

@@ -180,5 +184,5 @@ var DAY = 864e5;

await import_promises.default.writeFile(cfPath, cfText, "utf8");
this.ctx.log.info("Updated Request cf object cache!");
this.ctx.log.info("Updated `Request.cf` object cache!");
} catch (e) {
this.ctx.log.error(e);
this.ctx.log.warn("Unable to fetch the `Request.cf` object! Falling back to a default placeholder...\nTo always use the placeholder, set the `--no-cf-fetch`/`cfFetch: false` option.\n" + (0, import_colors.dim)(e.cause ? e.cause.stack : e.stack));
}

@@ -453,2 +457,58 @@ }

}
async function writeResponse(response, res, liveReload = false, log) {
const headers = {};
for (let [key, value] of response.headers) {
key = key.toLowerCase();
if (key === "set-cookie") {
headers["set-cookie"] = response.headers.getAll("set-cookie");
} else {
headers[key] = value;
}
}
const contentLengthHeader = response.headers.get("Content-Length");
const contentLength = (0, import_core._getBodyLength)(response) ?? (contentLengthHeader === null ? null : parseInt(contentLengthHeader));
if (contentLength !== null)
headers["content-length"] = contentLength;
const encoders = [];
if (headers["content-encoding"] && response.encodeBody === "auto") {
delete headers["content-length"];
const codings = headers["content-encoding"].toString().toLowerCase().split(",").map((x) => x.trim());
for (const coding of codings) {
if (/(x-)?gzip/.test(coding)) {
encoders.push(import_zlib.default.createGzip());
} else if (/(x-)?deflate/.test(coding)) {
encoders.push(import_zlib.default.createDeflate());
} else if (coding === "br") {
encoders.push(import_zlib.default.createBrotliCompress());
} else {
log?.warn(`Unknown encoding "${coding}", sending plain response...`);
delete headers["content-encoding"];
encoders.length = 0;
break;
}
}
}
const liveReloadEnabled = liveReload && response.encodeBody === "auto" && response.headers.get("content-type")?.toLowerCase().includes("text/html");
if (liveReloadEnabled && contentLength !== null) {
if (!isNaN(contentLength)) {
headers["content-length"] = contentLength + liveReloadScriptLength;
}
}
res.writeHead(response.status, headers);
let initialStream = res;
for (let i = encoders.length - 1; i >= 0; i--) {
encoders[i].pipe(initialStream);
initialStream = encoders[i];
}
if (response.body) {
for await (const chunk of response.body) {
if (chunk)
initialStream.write(chunk);
}
if (liveReloadEnabled) {
initialStream.write(liveReloadScript);
}
}
initialStream.end();
}
function createRequestListener(mf) {

@@ -480,57 +540,4 @@ return async (req, res) => {

status = response.status;
const headers = {};
for (let [key, value] of response.headers) {
key = key.toLowerCase();
if (key === "set-cookie") {
headers["set-cookie"] = response.headers.getAll("set-cookie");
} else {
headers[key] = value;
}
}
const contentLengthHeader = response.headers.get("Content-Length");
const contentLength = (0, import_core._getBodyLength)(response) ?? (contentLengthHeader === null ? null : parseInt(contentLengthHeader));
if (contentLength !== null)
headers["content-length"] = contentLength;
const encoders = [];
if (headers["content-encoding"] && response.encodeBody === "auto") {
delete headers["content-length"];
const codings = headers["content-encoding"].toString().toLowerCase().split(",").map((x) => x.trim());
for (const coding of codings) {
if (/(x-)?gzip/.test(coding)) {
encoders.push(import_zlib.default.createGzip());
} else if (/(x-)?deflate/.test(coding)) {
encoders.push(import_zlib.default.createDeflate());
} else if (coding === "br") {
encoders.push(import_zlib.default.createBrotliCompress());
} else {
mf.log.warn(`Unknown encoding "${coding}", sending plain response...`);
delete headers["content-encoding"];
encoders.length = 0;
break;
}
}
}
const liveReloadEnabled = HTTPPlugin2.liveReload && response.encodeBody === "auto" && response.headers.get("content-type")?.toLowerCase().includes("text/html");
if (liveReloadEnabled && contentLength !== null) {
if (!isNaN(contentLength)) {
headers["content-length"] = contentLength + liveReloadScriptLength;
}
}
res?.writeHead(status, headers);
if (res) {
let initialStream = res;
for (let i = encoders.length - 1; i >= 0; i--) {
encoders[i].pipe(initialStream);
initialStream = encoders[i];
}
if (response.body) {
for await (const chunk of response.body) {
if (chunk)
initialStream.write(chunk);
}
if (liveReloadEnabled) {
initialStream.write(liveReloadScript);
}
}
initialStream.end();
await writeResponse(response, res, HTTPPlugin2.liveReload, mf.log);
}

@@ -614,13 +621,20 @@ } catch (e) {

const webSocket = response?.webSocket;
if (response?.status !== 101 || !webSocket) {
socket.write("HTTP/1.1 500 Internal Server Error\r\n\r\n");
socket.destroy();
if (response?.status === 101 && webSocket) {
extraHeaders.set(request, response.headers);
webSocketServer.handleUpgrade(request, socket, head, (ws) => {
void (0, import_web_sockets.coupleWebSocket)(ws, webSocket);
webSocketServer.emit("connection", ws, request);
});
return;
}
const res = new import_http.default.ServerResponse(request);
(0, import_assert.default)(socket instanceof import_net.default.Socket);
res.assignSocket(socket);
if (!response || 200 <= response.status && response.status < 300) {
res.writeHead(500);
res.end();
mf.log.error(new TypeError("Web Socket request did not return status 101 Switching Protocols response with Web Socket"));
return;
}
extraHeaders.set(request, response.headers);
webSocketServer.handleUpgrade(request, socket, head, (ws) => {
void (0, import_web_sockets.coupleWebSocket)(ws, webSocket);
webSocketServer.emit("connection", ws, request);
});
await writeResponse(response, res, false, mf.log);
}

@@ -627,0 +641,0 @@ });

{
"name": "@miniflare/http-server",
"version": "2.5.1",
"version": "2.6.0-d1.1",
"description": "HTTP server module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers",

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

"dependencies": {
"@miniflare/core": "2.5.1",
"@miniflare/shared": "2.5.1",
"@miniflare/web-sockets": "2.5.1",
"@miniflare/core": "2.6.0-d1.1",
"@miniflare/shared": "2.6.0-d1.1",
"@miniflare/web-sockets": "2.6.0-d1.1",
"kleur": "^4.1.4",

@@ -49,5 +49,5 @@ "selfsigned": "^2.0.0",

"devDependencies": {
"@miniflare/shared-test": "2.5.1",
"@miniflare/shared-test": "2.6.0-d1.1",
"@types/node-forge": "^0.10.4"
}
}

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