@miniflare/http-server
Advanced tools
Comparing version 2.5.1 to 2.6.0-d1.1
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43486
768
1
4
+ Added@miniflare/core@2.6.0-d1.1(transitive)
+ Added@miniflare/shared@2.6.0-d1.1(transitive)
+ Added@miniflare/watcher@2.6.0-d1.1(transitive)
+ Added@miniflare/web-sockets@2.6.0-d1.1(transitive)
+ Added@types/better-sqlite3@7.6.11(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbetter-sqlite3@7.6.2(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedchownr@1.1.4(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexpand-template@2.0.3(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedgithub-from-package@0.0.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addednapi-build-utils@1.0.2(transitive)
+ Addednode-abi@3.71.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedprebuild-install@7.1.2(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@4.0.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedtar-fs@2.1.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removed@miniflare/core@2.5.1(transitive)
- Removed@miniflare/shared@2.5.1(transitive)
- Removed@miniflare/watcher@2.5.1(transitive)
- Removed@miniflare/web-sockets@2.5.1(transitive)
Updated@miniflare/core@2.6.0-d1.1
Updated@miniflare/shared@2.6.0-d1.1