@hono/node-server
Advanced tools
| export { } | ||
| export { } |
| export { } | ||
| export { } |
+67
-8
@@ -43,2 +43,5 @@ "use strict"; | ||
| // src/listener.ts | ||
| var import_node_http22 = require("http2"); | ||
| // src/request.ts | ||
@@ -72,2 +75,3 @@ var import_node_http2 = require("http2"); | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -106,2 +110,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= import_node_stream.Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -355,2 +376,3 @@ init.body = import_node_stream.Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -401,6 +423,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -451,4 +475,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -466,11 +493,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof import_node_http22.Http2ServerRequest) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -511,3 +569,4 @@ }); | ||
| hostname: options.hostname, | ||
| overrideGlobalObjects: options.overrideGlobalObjects | ||
| overrideGlobalObjects: options.overrideGlobalObjects, | ||
| autoCleanupIncoming: options.autoCleanupIncoming | ||
| }); | ||
@@ -514,0 +573,0 @@ const createServer = options.createServer || import_node_http.createServer; |
+67
-8
| // src/server.ts | ||
| import { createServer as createServerHTTP } from "http"; | ||
| // src/listener.ts | ||
| import { Http2ServerRequest as Http2ServerRequest2 } from "http2"; | ||
| // src/request.ts | ||
@@ -32,2 +35,3 @@ import { Http2ServerRequest } from "http2"; | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -66,2 +70,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -315,2 +336,3 @@ init.body = Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -361,6 +383,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -411,4 +435,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -426,11 +453,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof Http2ServerRequest2) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -471,3 +529,4 @@ }); | ||
| hostname: options.hostname, | ||
| overrideGlobalObjects: options.overrideGlobalObjects | ||
| overrideGlobalObjects: options.overrideGlobalObjects, | ||
| autoCleanupIncoming: options.autoCleanupIncoming | ||
| }); | ||
@@ -474,0 +533,0 @@ const createServer = options.createServer || createServerHTTP; |
@@ -10,4 +10,5 @@ import { IncomingMessage, ServerResponse } from 'node:http'; | ||
| overrideGlobalObjects?: boolean; | ||
| autoCleanupIncoming?: boolean; | ||
| }) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>; | ||
| export { getRequestListener }; |
@@ -10,4 +10,5 @@ import { IncomingMessage, ServerResponse } from 'node:http'; | ||
| overrideGlobalObjects?: boolean; | ||
| autoCleanupIncoming?: boolean; | ||
| }) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>; | ||
| export { getRequestListener }; |
+63
-7
@@ -36,2 +36,3 @@ "use strict"; | ||
| module.exports = __toCommonJS(listener_exports); | ||
| var import_node_http22 = require("http2"); | ||
@@ -66,2 +67,3 @@ // src/request.ts | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -100,2 +102,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= import_node_stream.Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -349,2 +368,3 @@ init.body = import_node_stream.Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -395,6 +415,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -445,4 +467,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -460,11 +485,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof import_node_http22.Http2ServerRequest) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -471,0 +527,0 @@ }); |
+65
-7
@@ -0,1 +1,4 @@ | ||
| // src/listener.ts | ||
| import { Http2ServerRequest as Http2ServerRequest2 } from "http2"; | ||
| // src/request.ts | ||
@@ -29,2 +32,3 @@ import { Http2ServerRequest } from "http2"; | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -63,2 +67,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -312,2 +333,3 @@ init.body = Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -358,6 +380,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -408,4 +432,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -423,11 +450,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof Http2ServerRequest2) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -434,0 +492,0 @@ }); |
@@ -17,2 +17,6 @@ import { IncomingMessage } from 'node:http'; | ||
| } | ||
| type IncomingMessageWithWrapBodyStream = IncomingMessage & { | ||
| [wrapBodyStream]: boolean; | ||
| }; | ||
| declare const wrapBodyStream: unique symbol; | ||
| declare const abortControllerKey: unique symbol; | ||
@@ -22,2 +26,2 @@ declare const getAbortController: unique symbol; | ||
| export { GlobalRequest, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError }; | ||
| export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream }; |
@@ -17,2 +17,6 @@ import { IncomingMessage } from 'node:http'; | ||
| } | ||
| type IncomingMessageWithWrapBodyStream = IncomingMessage & { | ||
| [wrapBodyStream]: boolean; | ||
| }; | ||
| declare const wrapBodyStream: unique symbol; | ||
| declare const abortControllerKey: unique symbol; | ||
@@ -22,2 +26,2 @@ declare const getAbortController: unique symbol; | ||
| export { GlobalRequest, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError }; | ||
| export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream }; |
+22
-2
@@ -29,3 +29,4 @@ "use strict"; | ||
| newRequest: () => newRequest, | ||
| toRequestError: () => toRequestError | ||
| toRequestError: () => toRequestError, | ||
| wrapBodyStream: () => wrapBodyStream | ||
| }); | ||
@@ -60,2 +61,3 @@ module.exports = __toCommonJS(request_exports); | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -94,2 +96,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= import_node_stream.Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -202,3 +221,4 @@ init.body = import_node_stream.Readable.toWeb(incoming); | ||
| newRequest, | ||
| toRequestError | ||
| toRequestError, | ||
| wrapBodyStream | ||
| }); |
+20
-1
@@ -29,2 +29,3 @@ // src/request.ts | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -63,2 +64,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -170,3 +188,4 @@ init.body = Readable.toWeb(incoming); | ||
| newRequest, | ||
| toRequestError | ||
| toRequestError, | ||
| wrapBodyStream | ||
| }; |
@@ -26,2 +26,2 @@ import { OutgoingHttpHeaders } from 'node:http'; | ||
| export { GlobalResponse, type InternalCache, Response, cacheKey }; | ||
| export { GlobalResponse, InternalCache, Response, cacheKey }; |
@@ -26,2 +26,2 @@ import { OutgoingHttpHeaders } from 'node:http'; | ||
| export { GlobalResponse, type InternalCache, Response, cacheKey }; | ||
| export { GlobalResponse, InternalCache, Response, cacheKey }; |
@@ -17,2 +17,2 @@ import { Env, Context, MiddlewareHandler } from 'hono'; | ||
| export { type ServeStaticOptions, serveStatic }; | ||
| export { ServeStaticOptions, serveStatic }; |
@@ -17,2 +17,2 @@ import { Env, Context, MiddlewareHandler } from 'hono'; | ||
| export { type ServeStaticOptions, serveStatic }; | ||
| export { ServeStaticOptions, serveStatic }; |
+67
-8
@@ -39,2 +39,5 @@ "use strict"; | ||
| // src/listener.ts | ||
| var import_node_http22 = require("http2"); | ||
| // src/request.ts | ||
@@ -68,2 +71,3 @@ var import_node_http2 = require("http2"); | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -102,2 +106,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= import_node_stream.Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -351,2 +372,3 @@ init.body = import_node_stream.Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -397,6 +419,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -447,4 +471,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -462,11 +489,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof import_node_http22.Http2ServerRequest) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -507,3 +565,4 @@ }); | ||
| hostname: options.hostname, | ||
| overrideGlobalObjects: options.overrideGlobalObjects | ||
| overrideGlobalObjects: options.overrideGlobalObjects, | ||
| autoCleanupIncoming: options.autoCleanupIncoming | ||
| }); | ||
@@ -510,0 +569,0 @@ const createServer = options.createServer || import_node_http.createServer; |
+67
-8
| // src/server.ts | ||
| import { createServer as createServerHTTP } from "http"; | ||
| // src/listener.ts | ||
| import { Http2ServerRequest as Http2ServerRequest2 } from "http2"; | ||
| // src/request.ts | ||
@@ -32,2 +35,3 @@ import { Http2ServerRequest } from "http2"; | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -66,2 +70,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -315,2 +336,3 @@ init.body = Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -361,6 +383,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -411,4 +435,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -426,11 +453,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof Http2ServerRequest2) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -471,3 +529,4 @@ }); | ||
| hostname: options.hostname, | ||
| overrideGlobalObjects: options.overrideGlobalObjects | ||
| overrideGlobalObjects: options.overrideGlobalObjects, | ||
| autoCleanupIncoming: options.autoCleanupIncoming | ||
| }); | ||
@@ -474,0 +533,0 @@ const createServer = options.createServer || createServerHTTP; |
+4
-3
@@ -1,3 +0,3 @@ | ||
| import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http'; | ||
| import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2'; | ||
| import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http'; | ||
| import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2'; | ||
| import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https'; | ||
@@ -38,2 +38,3 @@ | ||
| overrideGlobalObjects?: boolean; | ||
| autoCleanupIncoming?: boolean; | ||
| port?: number; | ||
@@ -44,2 +45,2 @@ hostname?: string; | ||
| export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType }; | ||
| export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType }; |
+4
-3
@@ -1,3 +0,3 @@ | ||
| import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http'; | ||
| import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2'; | ||
| import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http'; | ||
| import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2'; | ||
| import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https'; | ||
@@ -38,2 +38,3 @@ | ||
| overrideGlobalObjects?: boolean; | ||
| autoCleanupIncoming?: boolean; | ||
| port?: number; | ||
@@ -44,2 +45,2 @@ hostname?: string; | ||
| export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType }; | ||
| export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType }; |
+1
-1
| import { OutgoingHttpHeaders } from 'node:http'; | ||
| import { Writable } from 'node:stream'; | ||
| declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined; | ||
| declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined; | ||
| declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders; | ||
| export { buildOutgoingHttpHeaders, writeFromReadableStream }; |
+1
-1
| import { OutgoingHttpHeaders } from 'node:http'; | ||
| import { Writable } from 'node:stream'; | ||
| declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined; | ||
| declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined; | ||
| declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders; | ||
| export { buildOutgoingHttpHeaders, writeFromReadableStream }; |
+65
-7
@@ -37,2 +37,5 @@ "use strict"; | ||
| // src/listener.ts | ||
| var import_node_http22 = require("http2"); | ||
| // src/request.ts | ||
@@ -66,2 +69,3 @@ var import_node_http2 = require("http2"); | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -100,2 +104,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= import_node_stream.Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -349,2 +370,3 @@ init.body = import_node_stream.Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -395,6 +417,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -445,4 +469,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -460,11 +487,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof import_node_http22.Http2ServerRequest) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -471,0 +529,0 @@ }); |
+65
-7
@@ -0,1 +1,4 @@ | ||
| // src/listener.ts | ||
| import { Http2ServerRequest as Http2ServerRequest2 } from "http2"; | ||
| // src/request.ts | ||
@@ -29,2 +32,3 @@ import { Http2ServerRequest } from "http2"; | ||
| }; | ||
| var wrapBodyStream = Symbol("wrapBodyStream"); | ||
| var newRequestFromIncoming = (method, url, incoming, abortController) => { | ||
@@ -63,2 +67,19 @@ const headerRecord = []; | ||
| }); | ||
| } else if (incoming[wrapBodyStream]) { | ||
| let reader; | ||
| init.body = new ReadableStream({ | ||
| async pull(controller) { | ||
| try { | ||
| reader ||= Readable.toWeb(incoming).getReader(); | ||
| const { done, value } = await reader.read(); | ||
| if (done) { | ||
| controller.close(); | ||
| } else { | ||
| controller.enqueue(value); | ||
| } | ||
| } catch (error) { | ||
| controller.error(error); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
@@ -312,2 +333,3 @@ init.body = Readable.toWeb(incoming); | ||
| // src/listener.ts | ||
| var outgoingEnded = Symbol("outgoingEnded"); | ||
| var regBuffer = /^no$/i; | ||
@@ -358,6 +380,8 @@ var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i; | ||
| flushHeaders(outgoing); | ||
| return writeFromReadableStream(body, outgoing)?.catch( | ||
| await writeFromReadableStream(body, outgoing)?.catch( | ||
| (e) => handleResponseError(e, outgoing) | ||
| ); | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
@@ -408,4 +432,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => { | ||
| } | ||
| ; | ||
| outgoing[outgoingEnded]?.(); | ||
| }; | ||
| var getRequestListener = (fetchCallback, options = {}) => { | ||
| const autoCleanupIncoming = options.autoCleanupIncoming ?? true; | ||
| if (options.overrideGlobalObjects !== false && global.Request !== Request) { | ||
@@ -423,11 +450,42 @@ Object.defineProperty(global, "Request", { | ||
| req = newRequest(incoming, options.hostname); | ||
| let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD"; | ||
| if (!incomingEnded) { | ||
| ; | ||
| incoming[wrapBodyStream] = true; | ||
| incoming.on("end", () => { | ||
| incomingEnded = true; | ||
| }); | ||
| if (incoming instanceof Http2ServerRequest2) { | ||
| ; | ||
| outgoing[outgoingEnded] = () => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| outgoing.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| outgoing.on("close", () => { | ||
| const abortController = req[abortControllerKey]; | ||
| if (!abortController) { | ||
| return; | ||
| if (abortController) { | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| } | ||
| } | ||
| if (incoming.errored) { | ||
| req[abortControllerKey].abort(incoming.errored.toString()); | ||
| } else if (!outgoing.writableFinished) { | ||
| req[abortControllerKey].abort("Client connection prematurely closed."); | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| if (!incomingEnded) { | ||
| setTimeout(() => { | ||
| incoming.destroy(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
@@ -434,0 +492,0 @@ }); |
+1
-1
| { | ||
| "name": "@hono/node-server", | ||
| "version": "1.15.0", | ||
| "version": "1.16.0", | ||
| "description": "Node.js Adapter for Hono", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+12
-0
@@ -128,2 +128,14 @@ # Node.js Adapter for Hono | ||
| ### `autoCleanupIncoming` | ||
| The default value is `true`. The Node.js Adapter automatically cleans up (explicitly call `destroy()` method) if application is not finished to consume the incoming request. If you don't want to do that, set `false`. | ||
| If the application accepts connections from arbitrary clients, this cleanup must be done otherwise incomplete requests from clients may cause the application to stop responding. If your application only accepts connections from trusted clients, such as in a reverse proxy environment and there is no process that returns a response without reading the body of the POST request all the way through, you can improve performance by setting it to `false`. | ||
| ```ts | ||
| serve({ | ||
| fetch: app.fetch, | ||
| autoCleanupIncoming: false, | ||
| }) | ||
| ``` | ||
| ## Middleware | ||
@@ -130,0 +142,0 @@ |
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
193801
9.29%5695
9.71%340
3.66%66
13.79%