@adonisjs/http-server 8.1.1 → 8.1.2
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.
|
@@ -16,7 +16,7 @@ import onFinished from "on-finished";
|
|
|
16
16
|
import fresh from "fresh";
|
|
17
17
|
import typeIs from "type-is";
|
|
18
18
|
import { isIP } from "node:net";
|
|
19
|
-
import
|
|
19
|
+
import proxyAddr from "proxy-addr";
|
|
20
20
|
import { MessageBuilder, safeEqual } from "@poppinss/utils";
|
|
21
21
|
import lodash from "@poppinss/utils/lodash";
|
|
22
22
|
import base64 from "@poppinss/utils/base64";
|
|
@@ -870,11 +870,11 @@ var HttpRequest = class extends Macroable {
|
|
|
870
870
|
}
|
|
871
871
|
ip() {
|
|
872
872
|
const ipFn = this.#config.getIp;
|
|
873
|
-
if (typeof ipFn === "function") return ipFn(this, () =>
|
|
874
|
-
return
|
|
873
|
+
if (typeof ipFn === "function") return ipFn(this, () => proxyAddr(this.request, this.#config.trustProxy));
|
|
874
|
+
return proxyAddr(this.request, this.#config.trustProxy);
|
|
875
875
|
}
|
|
876
876
|
ips() {
|
|
877
|
-
return
|
|
877
|
+
return proxyAddr.all(this.request, this.#config.trustProxy);
|
|
878
878
|
}
|
|
879
879
|
protocol() {
|
|
880
880
|
if ("encrypted" in this.request.socket) return "https";
|
|
@@ -2374,9 +2374,19 @@ var Server = class {
|
|
|
2374
2374
|
return this.#serverMiddlewareStack ? Array.from(this.#serverMiddlewareStack.all()) : [...this.#middleware];
|
|
2375
2375
|
}
|
|
2376
2376
|
handle(req, res) {
|
|
2377
|
+
let request;
|
|
2378
|
+
try {
|
|
2379
|
+
request = this.createRequest(req, res);
|
|
2380
|
+
} catch (error) {
|
|
2381
|
+
if (error instanceof URIError) {
|
|
2382
|
+
this.#config.onBadUrl(req, res);
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
throw error;
|
|
2386
|
+
}
|
|
2377
2387
|
const startTime = this.#emitter.hasListeners("http:request_completed") ? process.hrtime() : null;
|
|
2378
2388
|
const resolver = this.#app.container.createResolver();
|
|
2379
|
-
const ctx = this.createHttpContext(
|
|
2389
|
+
const ctx = this.createHttpContext(request, this.createResponse(req, res), resolver);
|
|
2380
2390
|
if (startTime) onFinished(res, () => {
|
|
2381
2391
|
this.#emitter.emit("http:request_completed", {
|
|
2382
2392
|
ctx,
|
|
@@ -2391,7 +2401,7 @@ function defineConfig(config) {
|
|
|
2391
2401
|
const { trustProxy, ...rest } = config;
|
|
2392
2402
|
const defaults = {
|
|
2393
2403
|
allowMethodSpoofing: false,
|
|
2394
|
-
trustProxy:
|
|
2404
|
+
trustProxy: proxyAddr.compile("loopback"),
|
|
2395
2405
|
subdomainOffset: 2,
|
|
2396
2406
|
generateRequestId: !!config.createRequestId,
|
|
2397
2407
|
createRequestId() {
|
|
@@ -2408,6 +2418,10 @@ function defineConfig(config) {
|
|
|
2408
2418
|
secure: true,
|
|
2409
2419
|
sameSite: "lax"
|
|
2410
2420
|
},
|
|
2421
|
+
onBadUrl(_req, res) {
|
|
2422
|
+
res.writeHead(400, { "Content-Type": "text/plain" });
|
|
2423
|
+
res.end("Bad Request");
|
|
2424
|
+
},
|
|
2411
2425
|
qs: {
|
|
2412
2426
|
parse: {
|
|
2413
2427
|
depth: 5,
|
|
@@ -2431,7 +2445,7 @@ function defineConfig(config) {
|
|
|
2431
2445
|
normalizedConfig.trustProxy = (_, __) => tpValue;
|
|
2432
2446
|
} else if (typeof trustProxy === "string") {
|
|
2433
2447
|
const tpValue = trustProxy;
|
|
2434
|
-
normalizedConfig.trustProxy =
|
|
2448
|
+
normalizedConfig.trustProxy = proxyAddr.compile(tpValue);
|
|
2435
2449
|
} else if (trustProxy) normalizedConfig.trustProxy = trustProxy;
|
|
2436
2450
|
return normalizedConfig;
|
|
2437
2451
|
}
|
package/build/factories/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import "../utils-BjSHKI3s.js";
|
|
2
|
-
import { _ as Qs, c as HttpRequest, i as HttpResponse, n as Server, r as HttpContext, s as Router, t as defineConfig } from "../define_config-
|
|
2
|
+
import { _ as Qs, c as HttpRequest, i as HttpResponse, n as Server, r as HttpContext, s as Router, t as defineConfig } from "../define_config-BRmlbWlB.js";
|
|
3
3
|
import { t as createURL } from "../helpers-C_2HouOe.js";
|
|
4
4
|
import { parseRoute } from "../src/helpers.js";
|
|
5
5
|
import "../types-AUwURgIL.js";
|
|
6
6
|
import { Container } from "@adonisjs/fold";
|
|
7
7
|
import { Socket } from "node:net";
|
|
8
|
-
import
|
|
8
|
+
import proxyAddr from "proxy-addr";
|
|
9
9
|
import { safeStringify } from "@poppinss/utils/json";
|
|
10
10
|
import { AppFactory } from "@adonisjs/application/factories";
|
|
11
11
|
import { EncryptionFactory } from "@boringnode/encryption/factories";
|
|
@@ -60,7 +60,7 @@ var HttpRequestFactory = class {
|
|
|
60
60
|
#getConfig() {
|
|
61
61
|
return {
|
|
62
62
|
allowMethodSpoofing: false,
|
|
63
|
-
trustProxy:
|
|
63
|
+
trustProxy: proxyAddr.compile("loopback"),
|
|
64
64
|
subdomainOffset: 2,
|
|
65
65
|
generateRequestId: false,
|
|
66
66
|
createRequestId() {
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as RouteGroup, c as Route, m as canWriteResponseBody, o as RouteResource, p as tracing_channels_exports, s as BriskRoute, t as parseRange } from "./utils-BjSHKI3s.js";
|
|
2
|
-
import { _ as Qs, a as CookieSerializer, c as HttpRequest, d as Redirect, f as E_CANNOT_LOOKUP_ROUTE, g as errors_exports, h as E_ROUTE_NOT_FOUND, i as HttpResponse, l as CookieParser, m as E_HTTP_REQUEST_ABORTED, n as Server, o as ResponseStatus, p as E_HTTP_EXCEPTION, r as HttpContext, s as Router, t as defineConfig, u as CookieClient } from "./define_config-
|
|
2
|
+
import { _ as Qs, a as CookieSerializer, c as HttpRequest, d as Redirect, f as E_CANNOT_LOOKUP_ROUTE, g as errors_exports, h as E_ROUTE_NOT_FOUND, i as HttpResponse, l as CookieParser, m as E_HTTP_REQUEST_ABORTED, n as Server, o as ResponseStatus, p as E_HTTP_EXCEPTION, r as HttpContext, s as Router, t as defineConfig, u as CookieClient } from "./define_config-BRmlbWlB.js";
|
|
3
3
|
import "./helpers-C_2HouOe.js";
|
|
4
4
|
import "./types-AUwURgIL.js";
|
|
5
5
|
import Macroable from "@poppinss/macroable";
|
|
@@ -136,5 +136,5 @@ export declare class Server {
|
|
|
136
136
|
* @param res - Node.js ServerResponse
|
|
137
137
|
* @returns Promise that resolves when request processing is complete
|
|
138
138
|
*/
|
|
139
|
-
handle(req: IncomingMessage, res: ServerResponse): Promise<any
|
|
139
|
+
handle(req: IncomingMessage, res: ServerResponse): Promise<any> | undefined;
|
|
140
140
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
1
2
|
import type { Constructor } from '@poppinss/utils/types';
|
|
2
3
|
import type { ErrorHandler, FinalHandler } from '@poppinss/middleware/types';
|
|
3
4
|
import type { QSParserConfig } from './qs.ts';
|
|
@@ -115,4 +116,13 @@ export type ServerConfig = RequestConfig & ResponseConfig & {
|
|
|
115
116
|
* @default 0 (as per Node.js defaults)
|
|
116
117
|
*/
|
|
117
118
|
timeout?: number;
|
|
119
|
+
/**
|
|
120
|
+
* A callback invoked when the request URI contains malformed
|
|
121
|
+
* percent-encoded sequences (e.g. `%C0%80`). The callback
|
|
122
|
+
* receives the raw Node.js request and response objects and
|
|
123
|
+
* is responsible for sending a response.
|
|
124
|
+
*
|
|
125
|
+
* Defaults to a plain-text `400 Bad Request` response.
|
|
126
|
+
*/
|
|
127
|
+
onBadUrl: (req: IncomingMessage, res: ServerResponse) => void;
|
|
118
128
|
};
|