@hono/node-server 1.13.8 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -166,13 +166,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
166
166
  var newRequest = (incoming, defaultHostname) => {
167
167
  const req = Object.create(requestPrototype);
168
168
  req[incomingKey] = incoming;
169
+ const incomingUrl = incoming.url || "";
170
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
171
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
172
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
173
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
174
+ }
175
+ try {
176
+ const url2 = new URL(incomingUrl);
177
+ req[urlKey] = url2.href;
178
+ } catch (e) {
179
+ throw new RequestError("Invalid absolute URL", { cause: e });
180
+ }
181
+ return req;
182
+ }
169
183
  const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
170
184
  if (!host) {
171
185
  throw new RequestError("Missing host header");
172
186
  }
173
- const url = new URL(
174
- `${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
175
- );
187
+ let scheme;
188
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
189
+ scheme = incoming.scheme;
190
+ if (!(scheme === "http" || scheme === "https")) {
191
+ throw new RequestError("Unsupported scheme");
192
+ }
193
+ } else {
194
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
195
+ }
196
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
176
197
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
177
198
  throw new RequestError("Invalid host header");
178
199
  }
package/dist/index.mjs CHANGED
@@ -127,13 +127,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
127
127
  var newRequest = (incoming, defaultHostname) => {
128
128
  const req = Object.create(requestPrototype);
129
129
  req[incomingKey] = incoming;
130
+ const incomingUrl = incoming.url || "";
131
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
132
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
133
+ if (incoming instanceof Http2ServerRequest) {
134
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
135
+ }
136
+ try {
137
+ const url2 = new URL(incomingUrl);
138
+ req[urlKey] = url2.href;
139
+ } catch (e) {
140
+ throw new RequestError("Invalid absolute URL", { cause: e });
141
+ }
142
+ return req;
143
+ }
130
144
  const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
131
145
  if (!host) {
132
146
  throw new RequestError("Missing host header");
133
147
  }
134
- const url = new URL(
135
- `${incoming instanceof Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
136
- );
148
+ let scheme;
149
+ if (incoming instanceof Http2ServerRequest) {
150
+ scheme = incoming.scheme;
151
+ if (!(scheme === "http" || scheme === "https")) {
152
+ throw new RequestError("Unsupported scheme");
153
+ }
154
+ } else {
155
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
156
+ }
157
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
137
158
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
138
159
  throw new RequestError("Invalid host header");
139
160
  }
package/dist/listener.js CHANGED
@@ -160,13 +160,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
160
160
  var newRequest = (incoming, defaultHostname) => {
161
161
  const req = Object.create(requestPrototype);
162
162
  req[incomingKey] = incoming;
163
+ const incomingUrl = incoming.url || "";
164
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
165
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
166
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
167
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
168
+ }
169
+ try {
170
+ const url2 = new URL(incomingUrl);
171
+ req[urlKey] = url2.href;
172
+ } catch (e) {
173
+ throw new RequestError("Invalid absolute URL", { cause: e });
174
+ }
175
+ return req;
176
+ }
163
177
  const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
164
178
  if (!host) {
165
179
  throw new RequestError("Missing host header");
166
180
  }
167
- const url = new URL(
168
- `${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
169
- );
181
+ let scheme;
182
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
183
+ scheme = incoming.scheme;
184
+ if (!(scheme === "http" || scheme === "https")) {
185
+ throw new RequestError("Unsupported scheme");
186
+ }
187
+ } else {
188
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
189
+ }
190
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
170
191
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
171
192
  throw new RequestError("Invalid host header");
172
193
  }
package/dist/listener.mjs CHANGED
@@ -124,13 +124,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
124
124
  var newRequest = (incoming, defaultHostname) => {
125
125
  const req = Object.create(requestPrototype);
126
126
  req[incomingKey] = incoming;
127
+ const incomingUrl = incoming.url || "";
128
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
129
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
130
+ if (incoming instanceof Http2ServerRequest) {
131
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
132
+ }
133
+ try {
134
+ const url2 = new URL(incomingUrl);
135
+ req[urlKey] = url2.href;
136
+ } catch (e) {
137
+ throw new RequestError("Invalid absolute URL", { cause: e });
138
+ }
139
+ return req;
140
+ }
127
141
  const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
128
142
  if (!host) {
129
143
  throw new RequestError("Missing host header");
130
144
  }
131
- const url = new URL(
132
- `${incoming instanceof Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
133
- );
145
+ let scheme;
146
+ if (incoming instanceof Http2ServerRequest) {
147
+ scheme = incoming.scheme;
148
+ if (!(scheme === "http" || scheme === "https")) {
149
+ throw new RequestError("Unsupported scheme");
150
+ }
151
+ } else {
152
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
153
+ }
154
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
134
155
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
135
156
  throw new RequestError("Invalid host header");
136
157
  }
@@ -9,7 +9,7 @@ declare class RequestError extends Error {
9
9
  }
10
10
  declare const toRequestError: (e: unknown) => RequestError;
11
11
  declare const GlobalRequest: {
12
- new (input: RequestInfo | URL, init?: RequestInit | undefined): globalThis.Request;
12
+ new (input: RequestInfo | URL, init?: RequestInit): globalThis.Request;
13
13
  prototype: globalThis.Request;
14
14
  };
15
15
  declare class Request extends GlobalRequest {
package/dist/request.d.ts CHANGED
@@ -9,7 +9,7 @@ declare class RequestError extends Error {
9
9
  }
10
10
  declare const toRequestError: (e: unknown) => RequestError;
11
11
  declare const GlobalRequest: {
12
- new (input: RequestInfo | URL, init?: RequestInit | undefined): globalThis.Request;
12
+ new (input: RequestInfo | URL, init?: RequestInit): globalThis.Request;
13
13
  prototype: globalThis.Request;
14
14
  };
15
15
  declare class Request extends GlobalRequest {
package/dist/request.js CHANGED
@@ -154,13 +154,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
154
154
  var newRequest = (incoming, defaultHostname) => {
155
155
  const req = Object.create(requestPrototype);
156
156
  req[incomingKey] = incoming;
157
+ const incomingUrl = incoming.url || "";
158
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
159
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
160
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
161
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
162
+ }
163
+ try {
164
+ const url2 = new URL(incomingUrl);
165
+ req[urlKey] = url2.href;
166
+ } catch (e) {
167
+ throw new RequestError("Invalid absolute URL", { cause: e });
168
+ }
169
+ return req;
170
+ }
157
171
  const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
158
172
  if (!host) {
159
173
  throw new RequestError("Missing host header");
160
174
  }
161
- const url = new URL(
162
- `${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
163
- );
175
+ let scheme;
176
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
177
+ scheme = incoming.scheme;
178
+ if (!(scheme === "http" || scheme === "https")) {
179
+ throw new RequestError("Unsupported scheme");
180
+ }
181
+ } else {
182
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
183
+ }
184
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
164
185
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
165
186
  throw new RequestError("Invalid host header");
166
187
  }
package/dist/request.mjs CHANGED
@@ -124,13 +124,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
124
124
  var newRequest = (incoming, defaultHostname) => {
125
125
  const req = Object.create(requestPrototype);
126
126
  req[incomingKey] = incoming;
127
+ const incomingUrl = incoming.url || "";
128
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
129
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
130
+ if (incoming instanceof Http2ServerRequest) {
131
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
132
+ }
133
+ try {
134
+ const url2 = new URL(incomingUrl);
135
+ req[urlKey] = url2.href;
136
+ } catch (e) {
137
+ throw new RequestError("Invalid absolute URL", { cause: e });
138
+ }
139
+ return req;
140
+ }
127
141
  const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
128
142
  if (!host) {
129
143
  throw new RequestError("Missing host header");
130
144
  }
131
- const url = new URL(
132
- `${incoming instanceof Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
133
- );
145
+ let scheme;
146
+ if (incoming instanceof Http2ServerRequest) {
147
+ scheme = incoming.scheme;
148
+ if (!(scheme === "http" || scheme === "https")) {
149
+ throw new RequestError("Unsupported scheme");
150
+ }
151
+ } else {
152
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
153
+ }
154
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
134
155
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
135
156
  throw new RequestError("Invalid host header");
136
157
  }
@@ -6,11 +6,11 @@ interface InternalBody {
6
6
  declare const getResponseCache: unique symbol;
7
7
  declare const cacheKey: unique symbol;
8
8
  declare const GlobalResponse: {
9
- new (body?: BodyInit | null | undefined, init?: ResponseInit | undefined): globalThis.Response;
9
+ new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response;
10
10
  prototype: globalThis.Response;
11
11
  error(): globalThis.Response;
12
- json(data: any, init?: ResponseInit | undefined): globalThis.Response;
13
- redirect(url: string | URL, status?: number | undefined): globalThis.Response;
12
+ json(data: any, init?: ResponseInit): globalThis.Response;
13
+ redirect(url: string | URL, status?: number): globalThis.Response;
14
14
  };
15
15
  declare class Response {
16
16
  #private;
@@ -6,11 +6,11 @@ interface InternalBody {
6
6
  declare const getResponseCache: unique symbol;
7
7
  declare const cacheKey: unique symbol;
8
8
  declare const GlobalResponse: {
9
- new (body?: BodyInit | null | undefined, init?: ResponseInit | undefined): globalThis.Response;
9
+ new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response;
10
10
  prototype: globalThis.Response;
11
11
  error(): globalThis.Response;
12
- json(data: any, init?: ResponseInit | undefined): globalThis.Response;
13
- redirect(url: string | URL, status?: number | undefined): globalThis.Response;
12
+ json(data: any, init?: ResponseInit): globalThis.Response;
13
+ redirect(url: string | URL, status?: number): globalThis.Response;
14
14
  };
15
15
  declare class Response {
16
16
  #private;
@@ -25,7 +25,7 @@ __export(serve_static_exports, {
25
25
  module.exports = __toCommonJS(serve_static_exports);
26
26
  var import_filepath = require("hono/utils/filepath");
27
27
  var import_mime = require("hono/utils/mime");
28
- var import_fs = require("fs");
28
+ var import_node_fs = require("fs");
29
29
  var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
30
30
  var ENCODINGS = {
31
31
  br: ".br",
@@ -55,7 +55,7 @@ var addCurrentDirPrefix = (path) => {
55
55
  var getStats = (path) => {
56
56
  let stats;
57
57
  try {
58
- stats = (0, import_fs.lstatSync)(path);
58
+ stats = (0, import_node_fs.lstatSync)(path);
59
59
  } catch {
60
60
  }
61
61
  return stats;
@@ -129,7 +129,7 @@ var serveStatic = (options = { root: "" }) => {
129
129
  const range = c.req.header("range") || "";
130
130
  if (!range) {
131
131
  c.header("Content-Length", size.toString());
132
- return c.body(createStreamBody((0, import_fs.createReadStream)(path)), 200);
132
+ return c.body(createStreamBody((0, import_node_fs.createReadStream)(path)), 200);
133
133
  }
134
134
  c.header("Accept-Ranges", "bytes");
135
135
  c.header("Date", stats.birthtime.toUTCString());
@@ -140,7 +140,7 @@ var serveStatic = (options = { root: "" }) => {
140
140
  end = size - 1;
141
141
  }
142
142
  const chunksize = end - start + 1;
143
- const stream = (0, import_fs.createReadStream)(path, { start, end });
143
+ const stream = (0, import_node_fs.createReadStream)(path, { start, end });
144
144
  c.header("Content-Length", chunksize.toString());
145
145
  c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
146
146
  return c.body(createStreamBody(stream), 206);
package/dist/server.d.mts CHANGED
@@ -5,6 +5,6 @@ import 'node:http2';
5
5
  import 'node:https';
6
6
 
7
7
  declare const createAdaptorServer: (options: Options) => ServerType;
8
- declare const serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType;
8
+ declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
9
9
 
10
10
  export { createAdaptorServer, serve };
package/dist/server.d.ts CHANGED
@@ -5,6 +5,6 @@ import 'node:http2';
5
5
  import 'node:https';
6
6
 
7
7
  declare const createAdaptorServer: (options: Options) => ServerType;
8
- declare const serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType;
8
+ declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
9
9
 
10
10
  export { createAdaptorServer, serve };
package/dist/server.js CHANGED
@@ -162,13 +162,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
162
162
  var newRequest = (incoming, defaultHostname) => {
163
163
  const req = Object.create(requestPrototype);
164
164
  req[incomingKey] = incoming;
165
+ const incomingUrl = incoming.url || "";
166
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
167
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
168
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
169
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
170
+ }
171
+ try {
172
+ const url2 = new URL(incomingUrl);
173
+ req[urlKey] = url2.href;
174
+ } catch (e) {
175
+ throw new RequestError("Invalid absolute URL", { cause: e });
176
+ }
177
+ return req;
178
+ }
165
179
  const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
166
180
  if (!host) {
167
181
  throw new RequestError("Missing host header");
168
182
  }
169
- const url = new URL(
170
- `${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
171
- );
183
+ let scheme;
184
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
185
+ scheme = incoming.scheme;
186
+ if (!(scheme === "http" || scheme === "https")) {
187
+ throw new RequestError("Unsupported scheme");
188
+ }
189
+ } else {
190
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
191
+ }
192
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
172
193
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
173
194
  throw new RequestError("Invalid host header");
174
195
  }
package/dist/server.mjs CHANGED
@@ -127,13 +127,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
127
127
  var newRequest = (incoming, defaultHostname) => {
128
128
  const req = Object.create(requestPrototype);
129
129
  req[incomingKey] = incoming;
130
+ const incomingUrl = incoming.url || "";
131
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
132
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
133
+ if (incoming instanceof Http2ServerRequest) {
134
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
135
+ }
136
+ try {
137
+ const url2 = new URL(incomingUrl);
138
+ req[urlKey] = url2.href;
139
+ } catch (e) {
140
+ throw new RequestError("Invalid absolute URL", { cause: e });
141
+ }
142
+ return req;
143
+ }
130
144
  const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
131
145
  if (!host) {
132
146
  throw new RequestError("Missing host header");
133
147
  }
134
- const url = new URL(
135
- `${incoming instanceof Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
136
- );
148
+ let scheme;
149
+ if (incoming instanceof Http2ServerRequest) {
150
+ scheme = incoming.scheme;
151
+ if (!(scheme === "http" || scheme === "https")) {
152
+ throw new RequestError("Unsupported scheme");
153
+ }
154
+ } else {
155
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
156
+ }
157
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
137
158
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
138
159
  throw new RequestError("Invalid host header");
139
160
  }
package/dist/utils.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
4
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
5
5
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
6
6
 
7
7
  export { buildOutgoingHttpHeaders, writeFromReadableStream };
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
4
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
5
5
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
6
6
 
7
7
  export { buildOutgoingHttpHeaders, writeFromReadableStream };
package/dist/vercel.d.mts CHANGED
@@ -2,6 +2,6 @@ import * as http2 from 'http2';
2
2
  import * as http from 'http';
3
3
  import { Hono } from 'hono';
4
4
 
5
- declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse<http.IncomingMessage> | http2.Http2ServerResponse) => Promise<void>;
5
+ declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse | http2.Http2ServerResponse) => Promise<void>;
6
6
 
7
7
  export { handle };
package/dist/vercel.d.ts CHANGED
@@ -2,6 +2,6 @@ import * as http2 from 'http2';
2
2
  import * as http from 'http';
3
3
  import { Hono } from 'hono';
4
4
 
5
- declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse<http.IncomingMessage> | http2.Http2ServerResponse) => Promise<void>;
5
+ declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse | http2.Http2ServerResponse) => Promise<void>;
6
6
 
7
7
  export { handle };
package/dist/vercel.js CHANGED
@@ -160,13 +160,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
160
160
  var newRequest = (incoming, defaultHostname) => {
161
161
  const req = Object.create(requestPrototype);
162
162
  req[incomingKey] = incoming;
163
+ const incomingUrl = incoming.url || "";
164
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
165
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
166
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
167
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
168
+ }
169
+ try {
170
+ const url2 = new URL(incomingUrl);
171
+ req[urlKey] = url2.href;
172
+ } catch (e) {
173
+ throw new RequestError("Invalid absolute URL", { cause: e });
174
+ }
175
+ return req;
176
+ }
163
177
  const host = (incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
164
178
  if (!host) {
165
179
  throw new RequestError("Missing host header");
166
180
  }
167
- const url = new URL(
168
- `${incoming instanceof import_node_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
169
- );
181
+ let scheme;
182
+ if (incoming instanceof import_node_http2.Http2ServerRequest) {
183
+ scheme = incoming.scheme;
184
+ if (!(scheme === "http" || scheme === "https")) {
185
+ throw new RequestError("Unsupported scheme");
186
+ }
187
+ } else {
188
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
189
+ }
190
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
170
191
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
171
192
  throw new RequestError("Invalid host header");
172
193
  }
package/dist/vercel.mjs CHANGED
@@ -124,13 +124,34 @@ Object.setPrototypeOf(requestPrototype, Request.prototype);
124
124
  var newRequest = (incoming, defaultHostname) => {
125
125
  const req = Object.create(requestPrototype);
126
126
  req[incomingKey] = incoming;
127
+ const incomingUrl = incoming.url || "";
128
+ if (incomingUrl[0] !== "/" && // short-circuit for performance. most requests are relative URL.
129
+ (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
130
+ if (incoming instanceof Http2ServerRequest) {
131
+ throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
132
+ }
133
+ try {
134
+ const url2 = new URL(incomingUrl);
135
+ req[urlKey] = url2.href;
136
+ } catch (e) {
137
+ throw new RequestError("Invalid absolute URL", { cause: e });
138
+ }
139
+ return req;
140
+ }
127
141
  const host = (incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
128
142
  if (!host) {
129
143
  throw new RequestError("Missing host header");
130
144
  }
131
- const url = new URL(
132
- `${incoming instanceof Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
133
- );
145
+ let scheme;
146
+ if (incoming instanceof Http2ServerRequest) {
147
+ scheme = incoming.scheme;
148
+ if (!(scheme === "http" || scheme === "https")) {
149
+ throw new RequestError("Unsupported scheme");
150
+ }
151
+ } else {
152
+ scheme = incoming.socket && incoming.socket.encrypted ? "https" : "http";
153
+ }
154
+ const url = new URL(`${scheme}://${host}${incomingUrl}`);
134
155
  if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
135
156
  throw new RequestError("Invalid host header");
136
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.13.8",
3
+ "version": "1.14.0",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -58,7 +58,7 @@
58
58
  "build": "tsup --external hono",
59
59
  "watch": "tsup --watch",
60
60
  "postbuild": "publint",
61
- "prerelease": "yarn build && yarn test",
61
+ "prerelease": "bun run build && bun run test",
62
62
  "release": "np",
63
63
  "lint": "eslint src test",
64
64
  "lint:fix": "eslint src test --fix",