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

hono

Package Overview
Dependencies
Maintainers
1
Versions
342
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hono - npm Package Compare versions

Comparing version 4.2.5 to 4.2.6

168

dist/adapter/aws-lambda/handler.js

@@ -19,4 +19,5 @@ // src/adapter/aws-lambda/handler.ts

async (event, responseStream, context) => {
const processor = getProcessor(event);
try {
const req = createRequest(event);
const req = processor.createRequest(event);
const requestContext = getRequestContext(event);

@@ -49,3 +50,4 @@ const res = await app.fetch(req, {

return async (event, lambdaContext) => {
const req = createRequest(event);
const processor = getProcessor(event);
const req = processor.createRequest(event);
const requestContext = getRequestContext(event);

@@ -57,79 +59,111 @@ const res = await app.fetch(req, {

});
return createResult(event, res);
return processor.createResult(event, res);
};
};
var createResult = async (event, res) => {
const contentType = res.headers.get("content-type");
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
if (!isBase64Encoded) {
const contentEncoding = res.headers.get("content-encoding");
isBase64Encoded = isContentEncodingBinary(contentEncoding);
}
const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.text();
const result = {
body,
headers: {},
statusCode: res.status,
isBase64Encoded
};
setCookies(event, res, result);
res.headers.forEach((value, key) => {
result.headers[key] = value;
});
return result;
};
var createRequest = (event) => {
const queryString = extractQueryString(event);
const domainName = event.requestContext && "domainName" in event.requestContext ? event.requestContext.domainName : event.headers?.["host"] ?? event.multiValueHeaders?.["host"]?.[0];
const path = isProxyEventV2(event) ? event.rawPath : event.path;
const urlPath = `https://${domainName}${path}`;
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
const headers = new Headers();
getCookies(event, headers);
if (event.headers) {
for (const [k, v] of Object.entries(event.headers)) {
if (v) {
headers.set(k, v);
var EventProcessor = class {
createRequest(event) {
const queryString = this.getQueryString(event);
const domainName = event.requestContext && "domainName" in event.requestContext ? event.requestContext.domainName : event.headers?.["host"] ?? event.multiValueHeaders?.["host"]?.[0];
const path = this.getPath(event);
const urlPath = `https://${domainName}${path}`;
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
const headers = new Headers();
this.getCookies(event, headers);
if (event.headers) {
for (const [k, v] of Object.entries(event.headers)) {
if (v) {
headers.set(k, v);
}
}
}
if (event.multiValueHeaders) {
for (const [k, values] of Object.entries(event.multiValueHeaders)) {
if (values) {
values.forEach((v) => headers.append(k, v));
}
}
}
const method = this.getMethod(event);
const requestInit = {
headers,
method
};
if (event.body) {
requestInit.body = event.isBase64Encoded ? Buffer.from(event.body, "base64") : event.body;
}
return new Request(url, requestInit);
}
if (event.multiValueHeaders) {
for (const [k, values] of Object.entries(event.multiValueHeaders)) {
if (values) {
values.forEach((v) => headers.append(k, v));
async createResult(event, res) {
const contentType = res.headers.get("content-type");
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
if (!isBase64Encoded) {
const contentEncoding = res.headers.get("content-encoding");
isBase64Encoded = isContentEncodingBinary(contentEncoding);
}
const body = isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.text();
const result = {
body,
headers: {},
statusCode: res.status,
isBase64Encoded
};
this.setCookies(event, res, result);
res.headers.forEach((value, key) => {
result.headers[key] = value;
});
return result;
}
setCookies = (event, res, result) => {
if (res.headers.has("set-cookie")) {
const cookies = res.headers.get("set-cookie")?.split(", ");
if (Array.isArray(cookies)) {
this.setCookiesToResult(result, cookies);
res.headers.delete("set-cookie");
}
}
}
const method = isProxyEventV2(event) ? event.requestContext.http.method : event.httpMethod;
const requestInit = {
headers,
method
};
if (event.body) {
requestInit.body = event.isBase64Encoded ? Buffer.from(event.body, "base64") : event.body;
}
return new Request(url, requestInit);
};
var extractQueryString = (event) => {
return isProxyEventV2(event) ? event.rawQueryString : Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
};
var getCookies = (event, headers) => {
if (isProxyEventV2(event) && Array.isArray(event.cookies)) {
headers.set("Cookie", event.cookies.join("; "));
var v2Processor = new class EventV2Processor extends EventProcessor {
getPath(event) {
return event.rawPath;
}
};
var setCookies = (event, res, result) => {
if (res.headers.has("set-cookie")) {
const cookies = res.headers.get("set-cookie")?.split(", ");
if (Array.isArray(cookies)) {
if (isProxyEventV2(event)) {
result.cookies = cookies;
} else {
result.multiValueHeaders = {
"set-cookie": cookies
};
}
res.headers.delete("set-cookie");
getMethod(event) {
return event.requestContext.http.method;
}
getQueryString(event) {
return event.rawQueryString;
}
getCookies(event, headers) {
if (Array.isArray(event.cookies)) {
headers.set("Cookie", event.cookies.join("; "));
}
}
setCookiesToResult(result, cookies) {
result.cookies = cookies;
}
}();
var v1Processor = new class EventV1Processor extends EventProcessor {
getPath(event) {
return event.path;
}
getMethod(event) {
return event.httpMethod;
}
getQueryString(event) {
return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
}
getCookies(event, headers) {
}
setCookiesToResult(result, cookies) {
result.multiValueHeaders = {
"set-cookie": cookies
};
}
}();
var getProcessor = (event) => {
if (isProxyEventV2(event)) {
return v2Processor;
} else {
return v1Processor;
}
};

@@ -136,0 +170,0 @@ var isProxyEventV2 = (event) => {

@@ -50,4 +50,5 @@ "use strict";

async (event, responseStream, context) => {
const processor = getProcessor(event);
try {
const req = createRequest(event);
const req = processor.createRequest(event);
const requestContext = getRequestContext(event);

@@ -80,3 +81,4 @@ const res = await app.fetch(req, {

return async (event, lambdaContext) => {
const req = createRequest(event);
const processor = getProcessor(event);
const req = processor.createRequest(event);
const requestContext = getRequestContext(event);

@@ -88,79 +90,111 @@ const res = await app.fetch(req, {

});
return createResult(event, res);
return processor.createResult(event, res);
};
};
const createResult = async (event, res) => {
const contentType = res.headers.get("content-type");
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
if (!isBase64Encoded) {
const contentEncoding = res.headers.get("content-encoding");
isBase64Encoded = isContentEncodingBinary(contentEncoding);
}
const body = isBase64Encoded ? (0, import_encode.encodeBase64)(await res.arrayBuffer()) : await res.text();
const result = {
body,
headers: {},
statusCode: res.status,
isBase64Encoded
};
setCookies(event, res, result);
res.headers.forEach((value, key) => {
result.headers[key] = value;
});
return result;
};
const createRequest = (event) => {
const queryString = extractQueryString(event);
const domainName = event.requestContext && "domainName" in event.requestContext ? event.requestContext.domainName : event.headers?.["host"] ?? event.multiValueHeaders?.["host"]?.[0];
const path = isProxyEventV2(event) ? event.rawPath : event.path;
const urlPath = `https://${domainName}${path}`;
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
const headers = new Headers();
getCookies(event, headers);
if (event.headers) {
for (const [k, v] of Object.entries(event.headers)) {
if (v) {
headers.set(k, v);
class EventProcessor {
createRequest(event) {
const queryString = this.getQueryString(event);
const domainName = event.requestContext && "domainName" in event.requestContext ? event.requestContext.domainName : event.headers?.["host"] ?? event.multiValueHeaders?.["host"]?.[0];
const path = this.getPath(event);
const urlPath = `https://${domainName}${path}`;
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
const headers = new Headers();
this.getCookies(event, headers);
if (event.headers) {
for (const [k, v] of Object.entries(event.headers)) {
if (v) {
headers.set(k, v);
}
}
}
if (event.multiValueHeaders) {
for (const [k, values] of Object.entries(event.multiValueHeaders)) {
if (values) {
values.forEach((v) => headers.append(k, v));
}
}
}
const method = this.getMethod(event);
const requestInit = {
headers,
method
};
if (event.body) {
requestInit.body = event.isBase64Encoded ? Buffer.from(event.body, "base64") : event.body;
}
return new Request(url, requestInit);
}
if (event.multiValueHeaders) {
for (const [k, values] of Object.entries(event.multiValueHeaders)) {
if (values) {
values.forEach((v) => headers.append(k, v));
async createResult(event, res) {
const contentType = res.headers.get("content-type");
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
if (!isBase64Encoded) {
const contentEncoding = res.headers.get("content-encoding");
isBase64Encoded = isContentEncodingBinary(contentEncoding);
}
const body = isBase64Encoded ? (0, import_encode.encodeBase64)(await res.arrayBuffer()) : await res.text();
const result = {
body,
headers: {},
statusCode: res.status,
isBase64Encoded
};
this.setCookies(event, res, result);
res.headers.forEach((value, key) => {
result.headers[key] = value;
});
return result;
}
setCookies = (event, res, result) => {
if (res.headers.has("set-cookie")) {
const cookies = res.headers.get("set-cookie")?.split(", ");
if (Array.isArray(cookies)) {
this.setCookiesToResult(result, cookies);
res.headers.delete("set-cookie");
}
}
}
const method = isProxyEventV2(event) ? event.requestContext.http.method : event.httpMethod;
const requestInit = {
headers,
method
};
if (event.body) {
requestInit.body = event.isBase64Encoded ? Buffer.from(event.body, "base64") : event.body;
}
const v2Processor = new class EventV2Processor extends EventProcessor {
getPath(event) {
return event.rawPath;
}
return new Request(url, requestInit);
};
const extractQueryString = (event) => {
return isProxyEventV2(event) ? event.rawQueryString : Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
};
const getCookies = (event, headers) => {
if (isProxyEventV2(event) && Array.isArray(event.cookies)) {
headers.set("Cookie", event.cookies.join("; "));
getMethod(event) {
return event.requestContext.http.method;
}
};
const setCookies = (event, res, result) => {
if (res.headers.has("set-cookie")) {
const cookies = res.headers.get("set-cookie")?.split(", ");
if (Array.isArray(cookies)) {
if (isProxyEventV2(event)) {
result.cookies = cookies;
} else {
result.multiValueHeaders = {
"set-cookie": cookies
};
}
res.headers.delete("set-cookie");
getQueryString(event) {
return event.rawQueryString;
}
getCookies(event, headers) {
if (Array.isArray(event.cookies)) {
headers.set("Cookie", event.cookies.join("; "));
}
}
setCookiesToResult(result, cookies) {
result.cookies = cookies;
}
}();
const v1Processor = new class EventV1Processor extends EventProcessor {
getPath(event) {
return event.path;
}
getMethod(event) {
return event.httpMethod;
}
getQueryString(event) {
return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
}
getCookies(event, headers) {
}
setCookiesToResult(result, cookies) {
result.multiValueHeaders = {
"set-cookie": cookies
};
}
}();
const getProcessor = (event) => {
if (isProxyEventV2(event)) {
return v2Processor;
} else {
return v1Processor;
}
};

@@ -167,0 +201,0 @@ const isProxyEventV2 = (event) => {

@@ -29,4 +29,4 @@ "use strict";

const dirname = (path) => {
const splitedPath = path.split(/[\/\\]/);
return splitedPath.slice(0, -1).join("/");
const splittedPath = path.split(/[\/\\]/);
return splittedPath.slice(0, -1).join("/");
};

@@ -33,0 +33,0 @@ const normalizePath = (path) => {

@@ -56,2 +56,4 @@ "use strict";

}
} finally {
stream.close();
}

@@ -58,0 +60,0 @@ };

@@ -5,4 +5,4 @@ // src/helper/ssg/utils.ts

var dirname = (path) => {
const splitedPath = path.split(/[\/\\]/);
return splitedPath.slice(0, -1).join("/");
const splittedPath = path.split(/[\/\\]/);
return splittedPath.slice(0, -1).join("/");
};

@@ -9,0 +9,0 @@ var normalizePath = (path) => {

@@ -33,2 +33,4 @@ // src/helper/streaming/sse.ts

}
} finally {
stream.close();
}

@@ -35,0 +37,0 @@ };

@@ -26,11 +26,11 @@ import type { UpgradedWebSocketResponseInputJSONType } from '../helper/websocket';

} : {} : {}) => URL;
} & {
$ws: S['$get'] extends {
input: {
json: UpgradedWebSocketResponseInputJSONType;
};
} ? S['$get'] extends {
input: infer I;
} ? (args?: Omit<I, 'json'>) => WebSocket : never : never;
};
} & (S['$get'] extends {
input: {
json: UpgradedWebSocketResponseInputJSONType;
};
} ? S['$get'] extends {
input: infer I;
} ? {
$ws: (args?: Omit<I, 'json'>) => WebSocket;
} : {} : {});
type BlankRecordToNever<T> = T extends any ? T extends null ? null : keyof T extends never ? never : T : never;

@@ -37,0 +37,0 @@ export interface ClientResponse<T> {

@@ -12,3 +12,3 @@ import type { Context } from '../../context';

}
export type UpgradedWebSocketResponseInputJSONType = '__websocket' | undefined;
export type UpgradedWebSocketResponseInputJSONType = '__websocket';
/**

@@ -15,0 +15,0 @@ * Upgrade WebSocket Type

{
"name": "hono",
"version": "4.2.5",
"version": "4.2.6",
"description": "Ultrafast web framework for the Edges",

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

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