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

@hono/node-server

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hono/node-server - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

dist/utils.d.mts

67

dist/index.js

@@ -44,3 +44,2 @@ "use strict";

var import_node_stream = require("stream");
var import_promises = require("stream/promises");

@@ -63,2 +62,43 @@ // src/globals.ts

// src/utils.ts
function writeFromReadableStream(stream, writable) {
if (stream.locked) {
throw new TypeError("ReadableStream is locked.");
}
const reader = stream.getReader();
if (writable.destroyed) {
reader.cancel();
return;
}
writable.on("drain", onDrain);
writable.on("close", cancel);
writable.on("error", cancel);
reader.read().then(flow, cancel);
return reader.closed.finally(() => {
writable.off("close", cancel);
writable.off("error", cancel);
writable.off("drain", onDrain);
});
function cancel(error) {
reader.cancel(error).catch(() => {
});
if (error)
writable.destroy(error);
}
function onDrain() {
reader.read().then(flow, cancel);
}
function flow({ done, value }) {
try {
if (done) {
writable.end();
} else if (writable.write(value)) {
return reader.read().then(flow, cancel);
}
} catch (e) {
cancel(e);
}
}
}
// src/listener.ts

@@ -86,3 +126,3 @@ var regBuffer = /^no$/i;

try {
res = await fetchCallback(new Request(url.toString(), init));
res = await fetchCallback(new Request(url, init));
} catch (e) {

@@ -97,20 +137,24 @@ res = new Response(null, { status: 500 });

const resHeaderRecord = {};
const cookies = [];
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {
outgoing.setHeader(k, res.headers.getSetCookie(k));
cookies.push(v);
} else {
outgoing.setHeader(k, v);
resHeaderRecord[k] = v;
}
}
outgoing.statusCode = res.status;
if (cookies.length > 0) {
resHeaderRecord["set-cookie"] = cookies;
}
if (res.body) {
try {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
resHeaderRecord["x-accel-buffering"] && regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
outgoing.writeHead(res.status, resHeaderRecord);
await writeFromReadableStream(res.body, outgoing);
} else {
const text = await res.text();
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
outgoing.end(text);
const buffer = await res.arrayBuffer();
resHeaderRecord["content-length"] = buffer.byteLength;
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end(new Uint8Array(buffer));
}

@@ -127,2 +171,3 @@ } catch (e) {

} else {
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end();

@@ -129,0 +174,0 @@ }

@@ -37,3 +37,2 @@ "use strict";

var import_node_stream = require("stream");
var import_promises = require("stream/promises");

@@ -56,2 +55,43 @@ // src/globals.ts

// src/utils.ts
function writeFromReadableStream(stream, writable) {
if (stream.locked) {
throw new TypeError("ReadableStream is locked.");
}
const reader = stream.getReader();
if (writable.destroyed) {
reader.cancel();
return;
}
writable.on("drain", onDrain);
writable.on("close", cancel);
writable.on("error", cancel);
reader.read().then(flow, cancel);
return reader.closed.finally(() => {
writable.off("close", cancel);
writable.off("error", cancel);
writable.off("drain", onDrain);
});
function cancel(error) {
reader.cancel(error).catch(() => {
});
if (error)
writable.destroy(error);
}
function onDrain() {
reader.read().then(flow, cancel);
}
function flow({ done, value }) {
try {
if (done) {
writable.end();
} else if (writable.write(value)) {
return reader.read().then(flow, cancel);
}
} catch (e) {
cancel(e);
}
}
}
// src/listener.ts

@@ -79,3 +119,3 @@ var regBuffer = /^no$/i;

try {
res = await fetchCallback(new Request(url.toString(), init));
res = await fetchCallback(new Request(url, init));
} catch (e) {

@@ -90,20 +130,24 @@ res = new Response(null, { status: 500 });

const resHeaderRecord = {};
const cookies = [];
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {
outgoing.setHeader(k, res.headers.getSetCookie(k));
cookies.push(v);
} else {
outgoing.setHeader(k, v);
resHeaderRecord[k] = v;
}
}
outgoing.statusCode = res.status;
if (cookies.length > 0) {
resHeaderRecord["set-cookie"] = cookies;
}
if (res.body) {
try {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
resHeaderRecord["x-accel-buffering"] && regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
outgoing.writeHead(res.status, resHeaderRecord);
await writeFromReadableStream(res.body, outgoing);
} else {
const text = await res.text();
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
outgoing.end(text);
const buffer = await res.arrayBuffer();
resHeaderRecord["content-length"] = buffer.byteLength;
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end(new Uint8Array(buffer));
}

@@ -120,2 +164,3 @@ } catch (e) {

} else {
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end();

@@ -122,0 +167,0 @@ }

@@ -41,3 +41,2 @@ "use strict";

var import_node_stream = require("stream");
var import_promises = require("stream/promises");

@@ -60,2 +59,43 @@ // src/globals.ts

// src/utils.ts
function writeFromReadableStream(stream, writable) {
if (stream.locked) {
throw new TypeError("ReadableStream is locked.");
}
const reader = stream.getReader();
if (writable.destroyed) {
reader.cancel();
return;
}
writable.on("drain", onDrain);
writable.on("close", cancel);
writable.on("error", cancel);
reader.read().then(flow, cancel);
return reader.closed.finally(() => {
writable.off("close", cancel);
writable.off("error", cancel);
writable.off("drain", onDrain);
});
function cancel(error) {
reader.cancel(error).catch(() => {
});
if (error)
writable.destroy(error);
}
function onDrain() {
reader.read().then(flow, cancel);
}
function flow({ done, value }) {
try {
if (done) {
writable.end();
} else if (writable.write(value)) {
return reader.read().then(flow, cancel);
}
} catch (e) {
cancel(e);
}
}
}
// src/listener.ts

@@ -83,3 +123,3 @@ var regBuffer = /^no$/i;

try {
res = await fetchCallback(new Request(url.toString(), init));
res = await fetchCallback(new Request(url, init));
} catch (e) {

@@ -94,20 +134,24 @@ res = new Response(null, { status: 500 });

const resHeaderRecord = {};
const cookies = [];
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {
outgoing.setHeader(k, res.headers.getSetCookie(k));
cookies.push(v);
} else {
outgoing.setHeader(k, v);
resHeaderRecord[k] = v;
}
}
outgoing.statusCode = res.status;
if (cookies.length > 0) {
resHeaderRecord["set-cookie"] = cookies;
}
if (res.body) {
try {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
resHeaderRecord["x-accel-buffering"] && regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
outgoing.writeHead(res.status, resHeaderRecord);
await writeFromReadableStream(res.body, outgoing);
} else {
const text = await res.text();
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
outgoing.end(text);
const buffer = await res.arrayBuffer();
resHeaderRecord["content-length"] = buffer.byteLength;
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end(new Uint8Array(buffer));
}

@@ -124,2 +168,3 @@ } catch (e) {

} else {
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end();

@@ -126,0 +171,0 @@ }

@@ -39,3 +39,2 @@ "use strict";

var import_node_stream = require("stream");
var import_promises = require("stream/promises");

@@ -58,2 +57,43 @@ // src/globals.ts

// src/utils.ts
function writeFromReadableStream(stream, writable) {
if (stream.locked) {
throw new TypeError("ReadableStream is locked.");
}
const reader = stream.getReader();
if (writable.destroyed) {
reader.cancel();
return;
}
writable.on("drain", onDrain);
writable.on("close", cancel);
writable.on("error", cancel);
reader.read().then(flow, cancel);
return reader.closed.finally(() => {
writable.off("close", cancel);
writable.off("error", cancel);
writable.off("drain", onDrain);
});
function cancel(error) {
reader.cancel(error).catch(() => {
});
if (error)
writable.destroy(error);
}
function onDrain() {
reader.read().then(flow, cancel);
}
function flow({ done, value }) {
try {
if (done) {
writable.end();
} else if (writable.write(value)) {
return reader.read().then(flow, cancel);
}
} catch (e) {
cancel(e);
}
}
}
// src/listener.ts

@@ -81,3 +121,3 @@ var regBuffer = /^no$/i;

try {
res = await fetchCallback(new Request(url.toString(), init));
res = await fetchCallback(new Request(url, init));
} catch (e) {

@@ -92,20 +132,24 @@ res = new Response(null, { status: 500 });

const resHeaderRecord = {};
const cookies = [];
for (const [k, v] of res.headers) {
resHeaderRecord[k] = v;
if (k === "set-cookie") {
outgoing.setHeader(k, res.headers.getSetCookie(k));
cookies.push(v);
} else {
outgoing.setHeader(k, v);
resHeaderRecord[k] = v;
}
}
outgoing.statusCode = res.status;
if (cookies.length > 0) {
resHeaderRecord["set-cookie"] = cookies;
}
if (res.body) {
try {
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
resHeaderRecord["x-accel-buffering"] && regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
outgoing.writeHead(res.status, resHeaderRecord);
await writeFromReadableStream(res.body, outgoing);
} else {
const text = await res.text();
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
outgoing.end(text);
const buffer = await res.arrayBuffer();
resHeaderRecord["content-length"] = buffer.byteLength;
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end(new Uint8Array(buffer));
}

@@ -122,2 +166,3 @@ } catch (e) {

} else {
outgoing.writeHead(res.status, resHeaderRecord);
outgoing.end();

@@ -124,0 +169,0 @@ }

2

package.json
{
"name": "@hono/node-server",
"version": "1.2.1",
"version": "1.2.2",
"description": "Node.js Adapter for Hono",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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