Sign In

@hono/node-server

Package Overview
Dependencies
Maintainers
1
Versions
101
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
2.1.0
to
2.1.1
+151
-9
dist/index.cjs

@@ -17,2 +17,153 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

//#endregion
//#region src/headers.ts
const nonJoinedHeaders = new Set([
"age",
"authorization",
"content-length",
"content-type",
"etag",
"expires",
"from",
"host",
"if-modified-since",
"if-unmodified-since",
"last-modified",
"location",
"max-forwards",
"proxy-authorization",
"referer",
"retry-after",
"server",
"user-agent"
]);
const validHeaderName = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
const isHttpWhitespace = (code) => code === 9 || code === 10 || code === 13 || code === 32;
const normalizeHeaderValue = (value) => {
if (!isHttpWhitespace(value.charCodeAt(0)) && !isHttpWhitespace(value.charCodeAt(value.length - 1))) return value;
let start = 0;
let end = value.length;
while (start < end && isHttpWhitespace(value.charCodeAt(start))) start++;
while (end > start && isHttpWhitespace(value.charCodeAt(end - 1))) end--;
return value.slice(start, end);
};
const forbiddenHeaderValue = /[\0\r\n]/;
const GlobalHeaders = globalThis.Headers;
const materializeHeaders = (rawHeaders, HeadersCtor = GlobalHeaders) => {
const headers = new HeadersCtor();
for (let i = 0; i < rawHeaders.length; i += 2) {
const name = rawHeaders[i];
if (!name.startsWith(":")) headers.append(name, rawHeaders[i + 1]);
}
return headers;
};
var RequestHeaders = class {
#incoming;
#rawHeaders;
#headers;
#invalidValue;
constructor(incoming) {
this.#incoming = incoming;
if (incoming instanceof node_http2.Http2ServerRequest) this.#rawHeaders = incoming.rawHeaders.slice();
}
get #lazyRawHeaders() {
return this.#rawHeaders ??= this.#incoming.rawHeaders.slice();
}
get #native() {
if (!this.#headers) {
this.#headers = materializeHeaders(this.#lazyRawHeaders);
this.#rawHeaders = void 0;
}
return this.#headers;
}
#normalizedName(name) {
if (typeof name !== "string") return;
if (!validHeaderName.test(name)) throw new TypeError(`Invalid header name: ${name}`);
return name.toLowerCase();
}
#lookupHttp1(lowerName) {
const headers = this.#incoming instanceof node_http2.Http2ServerRequest ? void 0 : this.#incoming.headers;
if (!headers || nonJoinedHeaders.has(lowerName) || lowerName === "set-cookie" || lowerName === "__proto__") return;
if (!Object.hasOwn(headers, lowerName)) return null;
const rawValue = headers[lowerName];
if (typeof rawValue === "string") {
const value = normalizeHeaderValue(rawValue);
return forbiddenHeaderValue.test(value) ? void 0 : value;
}
}
#lookup(rawHeaders, lowerName) {
const separator = lowerName === "cookie" ? "; " : ", ";
let value = null;
for (let i = 0; i < rawHeaders.length; i += 2) {
const rawName = rawHeaders[i];
if (rawName.length === lowerName.length && rawName.toLowerCase() === lowerName) {
const rawValue = normalizeHeaderValue(rawHeaders[i + 1]);
if (forbiddenHeaderValue.test(rawValue)) {
this.#invalidValue = true;
return;
}
value = value === null ? rawValue : value + separator + rawValue;
}
}
return value;
}
append(name, value) {
this.#native.append(name, value);
}
delete(name) {
this.#native.delete(name);
}
get(name) {
const lowerName = this.#normalizedName(name);
if (lowerName && !this.#headers && !this.#invalidValue) {
const http1Value = this.#lookupHttp1(lowerName);
if (http1Value !== void 0) return http1Value;
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
if (value !== void 0) return value;
}
return this.#native.get(name);
}
has(name) {
const lowerName = this.#normalizedName(name);
if (lowerName && !this.#headers && !this.#invalidValue) {
const http1Value = this.#lookupHttp1(lowerName);
if (http1Value !== void 0) return http1Value !== null;
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
if (value !== void 0) return value !== null;
}
return this.#native.has(name);
}
set(name, value) {
this.#native.set(name, value);
}
getSetCookie() {
return this.#native.getSetCookie();
}
keys() {
return this.#native.keys();
}
values() {
return this.#native.values();
}
entries() {
return this.#native.entries();
}
forEach(callback, thisArg) {
this.#native.forEach((value, key) => {
callback.call(thisArg, value, key, this);
});
}
[Symbol.iterator]() {
return this.entries();
}
};
Object.defineProperty(RequestHeaders.prototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
return `Headers (lightweight) ${inspectFn(Object.fromEntries(this), {
...options,
depth: depth == null ? null : depth - 1
})}`;
} });
Object.setPrototypeOf(RequestHeaders.prototype, GlobalHeaders.prototype);
const newHeadersFromIncoming = (incoming) => globalThis.Headers === GlobalHeaders ? new RequestHeaders(incoming) : materializeHeaders(incoming.rawHeaders, globalThis.Headers);
//#endregion
//#region src/url.ts

@@ -54,11 +205,2 @@ const reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;

};
const newHeadersFromIncoming = (incoming) => {
const headerRecord = [];
const rawHeaders = incoming.rawHeaders;
for (let i = 0, len = rawHeaders.length; i < len; i += 2) {
const key = rawHeaders[i];
if (key.charCodeAt(0) !== 58) headerRecord.push([key, rawHeaders[i + 1]]);
}
return new Headers(headerRecord);
};
const wrapBodyStream = Symbol("wrapBodyStream");

@@ -65,0 +207,0 @@ const byteExactEncodings = new Set([

@@ -16,2 +16,153 @@ import { t as X_ALREADY_SENT } from "./constants-BLSFu_RU.mjs";

//#endregion
//#region src/headers.ts
const nonJoinedHeaders = new Set([
"age",
"authorization",
"content-length",
"content-type",
"etag",
"expires",
"from",
"host",
"if-modified-since",
"if-unmodified-since",
"last-modified",
"location",
"max-forwards",
"proxy-authorization",
"referer",
"retry-after",
"server",
"user-agent"
]);
const validHeaderName = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
const isHttpWhitespace = (code) => code === 9 || code === 10 || code === 13 || code === 32;
const normalizeHeaderValue = (value) => {
if (!isHttpWhitespace(value.charCodeAt(0)) && !isHttpWhitespace(value.charCodeAt(value.length - 1))) return value;
let start = 0;
let end = value.length;
while (start < end && isHttpWhitespace(value.charCodeAt(start))) start++;
while (end > start && isHttpWhitespace(value.charCodeAt(end - 1))) end--;
return value.slice(start, end);
};
const forbiddenHeaderValue = /[\0\r\n]/;
const GlobalHeaders = globalThis.Headers;
const materializeHeaders = (rawHeaders, HeadersCtor = GlobalHeaders) => {
const headers = new HeadersCtor();
for (let i = 0; i < rawHeaders.length; i += 2) {
const name = rawHeaders[i];
if (!name.startsWith(":")) headers.append(name, rawHeaders[i + 1]);
}
return headers;
};
var RequestHeaders = class {
#incoming;
#rawHeaders;
#headers;
#invalidValue;
constructor(incoming) {
this.#incoming = incoming;
if (incoming instanceof Http2ServerRequest) this.#rawHeaders = incoming.rawHeaders.slice();
}
get #lazyRawHeaders() {
return this.#rawHeaders ??= this.#incoming.rawHeaders.slice();
}
get #native() {
if (!this.#headers) {
this.#headers = materializeHeaders(this.#lazyRawHeaders);
this.#rawHeaders = void 0;
}
return this.#headers;
}
#normalizedName(name) {
if (typeof name !== "string") return;
if (!validHeaderName.test(name)) throw new TypeError(`Invalid header name: ${name}`);
return name.toLowerCase();
}
#lookupHttp1(lowerName) {
const headers = this.#incoming instanceof Http2ServerRequest ? void 0 : this.#incoming.headers;
if (!headers || nonJoinedHeaders.has(lowerName) || lowerName === "set-cookie" || lowerName === "__proto__") return;
if (!Object.hasOwn(headers, lowerName)) return null;
const rawValue = headers[lowerName];
if (typeof rawValue === "string") {
const value = normalizeHeaderValue(rawValue);
return forbiddenHeaderValue.test(value) ? void 0 : value;
}
}
#lookup(rawHeaders, lowerName) {
const separator = lowerName === "cookie" ? "; " : ", ";
let value = null;
for (let i = 0; i < rawHeaders.length; i += 2) {
const rawName = rawHeaders[i];
if (rawName.length === lowerName.length && rawName.toLowerCase() === lowerName) {
const rawValue = normalizeHeaderValue(rawHeaders[i + 1]);
if (forbiddenHeaderValue.test(rawValue)) {
this.#invalidValue = true;
return;
}
value = value === null ? rawValue : value + separator + rawValue;
}
}
return value;
}
append(name, value) {
this.#native.append(name, value);
}
delete(name) {
this.#native.delete(name);
}
get(name) {
const lowerName = this.#normalizedName(name);
if (lowerName && !this.#headers && !this.#invalidValue) {
const http1Value = this.#lookupHttp1(lowerName);
if (http1Value !== void 0) return http1Value;
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
if (value !== void 0) return value;
}
return this.#native.get(name);
}
has(name) {
const lowerName = this.#normalizedName(name);
if (lowerName && !this.#headers && !this.#invalidValue) {
const http1Value = this.#lookupHttp1(lowerName);
if (http1Value !== void 0) return http1Value !== null;
const value = this.#lookup(this.#lazyRawHeaders, lowerName);
if (value !== void 0) return value !== null;
}
return this.#native.has(name);
}
set(name, value) {
this.#native.set(name, value);
}
getSetCookie() {
return this.#native.getSetCookie();
}
keys() {
return this.#native.keys();
}
values() {
return this.#native.values();
}
entries() {
return this.#native.entries();
}
forEach(callback, thisArg) {
this.#native.forEach((value, key) => {
callback.call(thisArg, value, key, this);
});
}
[Symbol.iterator]() {
return this.entries();
}
};
Object.defineProperty(RequestHeaders.prototype, Symbol.for("nodejs.util.inspect.custom"), { value: function(depth, options, inspectFn) {
return `Headers (lightweight) ${inspectFn(Object.fromEntries(this), {
...options,
depth: depth == null ? null : depth - 1
})}`;
} });
Object.setPrototypeOf(RequestHeaders.prototype, GlobalHeaders.prototype);
const newHeadersFromIncoming = (incoming) => globalThis.Headers === GlobalHeaders ? new RequestHeaders(incoming) : materializeHeaders(incoming.rawHeaders, globalThis.Headers);
//#endregion
//#region src/url.ts

@@ -53,11 +204,2 @@ const reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;

};
const newHeadersFromIncoming = (incoming) => {
const headerRecord = [];
const rawHeaders = incoming.rawHeaders;
for (let i = 0, len = rawHeaders.length; i < len; i += 2) {
const key = rawHeaders[i];
if (key.charCodeAt(0) !== 58) headerRecord.push([key, rawHeaders[i + 1]]);
}
return new Headers(headerRecord);
};
const wrapBodyStream = Symbol("wrapBodyStream");

@@ -64,0 +206,0 @@ const byteExactEncodings = new Set([

+1
-1
{
"name": "@hono/node-server",
"version": "2.1.0",
"version": "2.1.1",
"description": "Node.js Adapter for Hono",

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