@nodefony/http 10.0.0-alpha.1
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/LICENSE +544 -0
- package/README.md +77 -0
- package/dist/_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/decorateMetadata.js +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/decorateParam.js +8 -0
- package/dist/index.js +108 -0
- package/dist/nodefony/command/assetsPublishCommand.js +102 -0
- package/dist/nodefony/command/certificatesCommand.js +47 -0
- package/dist/nodefony/command/networkCommand.js +27 -0
- package/dist/nodefony/command/proxyGenerateCommand.js +66 -0
- package/dist/nodefony/config/config.js +335 -0
- package/dist/nodefony/config/defineModuleConfig.js +93 -0
- package/dist/nodefony/interfaces/IContext.js +1 -0
- package/dist/nodefony/interfaces/ICookie.js +1 -0
- package/dist/nodefony/interfaces/IErrorRenderer.js +1 -0
- package/dist/nodefony/interfaces/IHttpConfig.js +1 -0
- package/dist/nodefony/interfaces/IHttpKernel.js +1 -0
- package/dist/nodefony/interfaces/IRequest.js +1 -0
- package/dist/nodefony/interfaces/IRequestLogger.js +1 -0
- package/dist/nodefony/interfaces/IResponse.js +1 -0
- package/dist/nodefony/interfaces/ISession.js +1 -0
- package/dist/nodefony/interfaces/IUpload.js +1 -0
- package/dist/nodefony/interfaces/index.js +1 -0
- package/dist/nodefony/service/HttpAdminApi.js +376 -0
- package/dist/nodefony/service/ProfilerAdminApi.js +73 -0
- package/dist/nodefony/service/audit-logger.js +159 -0
- package/dist/nodefony/service/certificates.js +545 -0
- package/dist/nodefony/service/error-renderer.js +320 -0
- package/dist/nodefony/service/http-kernel.js +948 -0
- package/dist/nodefony/service/pretty-request-logger.js +72 -0
- package/dist/nodefony/service/request-logger.js +54 -0
- package/dist/nodefony/service/servers/clientError.js +20 -0
- package/dist/nodefony/service/servers/server-http.js +135 -0
- package/dist/nodefony/service/servers/server-https.js +204 -0
- package/dist/nodefony/service/servers/server-static.js +192 -0
- package/dist/nodefony/service/servers/server-websocket-secure.js +104 -0
- package/dist/nodefony/service/servers/server-websocket.js +104 -0
- package/dist/nodefony/service/servers/serverShutdown.js +31 -0
- package/dist/nodefony/service/servers/wsHeartbeat.js +64 -0
- package/dist/nodefony/service/sessions/sessions-service.js +580 -0
- package/dist/nodefony/service/trace.js +72 -0
- package/dist/nodefony/service/upload/upload-service.js +171 -0
- package/dist/nodefony/src/assets/collectAssets.js +34 -0
- package/dist/nodefony/src/assets/prebuiltUi.js +125 -0
- package/dist/nodefony/src/context/Context.js +415 -0
- package/dist/nodefony/src/context/domainMatcher.js +88 -0
- package/dist/nodefony/src/context/forwarded.js +185 -0
- package/dist/nodefony/src/context/http/HttpContext.js +309 -0
- package/dist/nodefony/src/context/http/Request.js +543 -0
- package/dist/nodefony/src/context/http/Response.js +368 -0
- package/dist/nodefony/src/context/http/parser.js +188 -0
- package/dist/nodefony/src/context/http/urlFastPath.js +103 -0
- package/dist/nodefony/src/context/http2/Request.js +29 -0
- package/dist/nodefony/src/context/http2/Response.js +97 -0
- package/dist/nodefony/src/context/metaData.js +47 -0
- package/dist/nodefony/src/context/requestId.js +41 -0
- package/dist/nodefony/src/context/trustProxy.js +167 -0
- package/dist/nodefony/src/context/websocket/Response.js +181 -0
- package/dist/nodefony/src/context/websocket/WebsocketContext.js +389 -0
- package/dist/nodefony/src/context/websocket/wsBackpressure.js +56 -0
- package/dist/nodefony/src/context/websocket/wsLogContent.js +68 -0
- package/dist/nodefony/src/cookies/cookie.js +258 -0
- package/dist/nodefony/src/errors/httpError.js +69 -0
- package/dist/nodefony/src/profiler/FrameProfile.js +95 -0
- package/dist/nodefony/src/profiler/Profiler.js +139 -0
- package/dist/nodefony/src/proxy/generateProxyConfig.js +157 -0
- package/dist/nodefony/src/rateLimit/IRateLimitStore.js +1 -0
- package/dist/nodefony/src/rateLimit/MemoryRateLimitStore.js +146 -0
- package/dist/nodefony/src/rateLimit/WsConnectionCounter.js +64 -0
- package/dist/nodefony/src/rateLimit/rateLimitFilters.js +20 -0
- package/dist/nodefony/src/servers/portBinder.js +114 -0
- package/dist/nodefony/src/session/session.js +390 -0
- package/dist/nodefony/src/session/storage/MemorySessionStorage.js +185 -0
- package/dist/nodefony/src/session/storage/RevocationGuardStorage.js +137 -0
- package/dist/nodefony/src/session/storage/sessionFilters.js +83 -0
- package/dist/nodefony/src/session/storage/sessionSort.js +53 -0
- package/dist/types/index.d.ts +83 -0
- package/dist/types/nodefony/command/assetsPublishCommand.d.ts +23 -0
- package/dist/types/nodefony/command/certificatesCommand.d.ts +17 -0
- package/dist/types/nodefony/command/networkCommand.d.ts +8 -0
- package/dist/types/nodefony/command/proxyGenerateCommand.d.ts +19 -0
- package/dist/types/nodefony/config/config.d.ts +197 -0
- package/dist/types/nodefony/config/defineModuleConfig.d.ts +39 -0
- package/dist/types/nodefony/interfaces/IContext.d.ts +138 -0
- package/dist/types/nodefony/interfaces/ICookie.d.ts +47 -0
- package/dist/types/nodefony/interfaces/IErrorRenderer.d.ts +55 -0
- package/dist/types/nodefony/interfaces/IHttpConfig.d.ts +12 -0
- package/dist/types/nodefony/interfaces/IHttpKernel.d.ts +10 -0
- package/dist/types/nodefony/interfaces/IRequest.d.ts +35 -0
- package/dist/types/nodefony/interfaces/IRequestLogger.d.ts +31 -0
- package/dist/types/nodefony/interfaces/IResponse.d.ts +39 -0
- package/dist/types/nodefony/interfaces/ISession.d.ts +283 -0
- package/dist/types/nodefony/interfaces/IUpload.d.ts +66 -0
- package/dist/types/nodefony/interfaces/index.d.ts +7 -0
- package/dist/types/nodefony/service/HttpAdminApi.d.ts +18 -0
- package/dist/types/nodefony/service/ProfilerAdminApi.d.ts +23 -0
- package/dist/types/nodefony/service/audit-logger.d.ts +143 -0
- package/dist/types/nodefony/service/certificates.d.ts +246 -0
- package/dist/types/nodefony/service/error-renderer.d.ts +74 -0
- package/dist/types/nodefony/service/http-kernel.d.ts +377 -0
- package/dist/types/nodefony/service/pretty-request-logger.d.ts +25 -0
- package/dist/types/nodefony/service/request-logger.d.ts +18 -0
- package/dist/types/nodefony/service/servers/clientError.d.ts +14 -0
- package/dist/types/nodefony/service/servers/server-http.d.ts +42 -0
- package/dist/types/nodefony/service/servers/server-https.d.ts +41 -0
- package/dist/types/nodefony/service/servers/server-static.d.ts +62 -0
- package/dist/types/nodefony/service/servers/server-websocket-secure.d.ts +29 -0
- package/dist/types/nodefony/service/servers/server-websocket.d.ts +29 -0
- package/dist/types/nodefony/service/servers/serverShutdown.d.ts +27 -0
- package/dist/types/nodefony/service/servers/wsHeartbeat.d.ts +46 -0
- package/dist/types/nodefony/service/sessions/sessions-service.d.ts +218 -0
- package/dist/types/nodefony/service/trace.d.ts +39 -0
- package/dist/types/nodefony/service/upload/upload-service.d.ts +61 -0
- package/dist/types/nodefony/src/assets/collectAssets.d.ts +35 -0
- package/dist/types/nodefony/src/assets/prebuiltUi.d.ts +99 -0
- package/dist/types/nodefony/src/context/Context.d.ts +195 -0
- package/dist/types/nodefony/src/context/domainMatcher.d.ts +67 -0
- package/dist/types/nodefony/src/context/forwarded.d.ts +95 -0
- package/dist/types/nodefony/src/context/http/HttpContext.d.ts +85 -0
- package/dist/types/nodefony/src/context/http/Request.d.ts +203 -0
- package/dist/types/nodefony/src/context/http/Response.d.ts +68 -0
- package/dist/types/nodefony/src/context/http/parser.d.ts +65 -0
- package/dist/types/nodefony/src/context/http/urlFastPath.d.ts +52 -0
- package/dist/types/nodefony/src/context/http2/Request.d.ts +14 -0
- package/dist/types/nodefony/src/context/http2/Response.d.ts +20 -0
- package/dist/types/nodefony/src/context/metaData.d.ts +58 -0
- package/dist/types/nodefony/src/context/requestId.d.ts +28 -0
- package/dist/types/nodefony/src/context/trustProxy.d.ts +77 -0
- package/dist/types/nodefony/src/context/websocket/Response.d.ts +53 -0
- package/dist/types/nodefony/src/context/websocket/WebsocketContext.d.ts +125 -0
- package/dist/types/nodefony/src/context/websocket/wsBackpressure.d.ts +73 -0
- package/dist/types/nodefony/src/context/websocket/wsLogContent.d.ts +37 -0
- package/dist/types/nodefony/src/cookies/cookie.d.ts +88 -0
- package/dist/types/nodefony/src/errors/httpError.d.ts +15 -0
- package/dist/types/nodefony/src/profiler/FrameProfile.d.ts +110 -0
- package/dist/types/nodefony/src/profiler/Profiler.d.ts +192 -0
- package/dist/types/nodefony/src/proxy/generateProxyConfig.d.ts +76 -0
- package/dist/types/nodefony/src/rateLimit/IRateLimitStore.d.ts +98 -0
- package/dist/types/nodefony/src/rateLimit/MemoryRateLimitStore.d.ts +40 -0
- package/dist/types/nodefony/src/rateLimit/WsConnectionCounter.d.ts +37 -0
- package/dist/types/nodefony/src/rateLimit/rateLimitFilters.d.ts +18 -0
- package/dist/types/nodefony/src/servers/portBinder.d.ts +102 -0
- package/dist/types/nodefony/src/session/session.d.ts +171 -0
- package/dist/types/nodefony/src/session/storage/MemorySessionStorage.d.ts +77 -0
- package/dist/types/nodefony/src/session/storage/RevocationGuardStorage.d.ts +81 -0
- package/dist/types/nodefony/src/session/storage/sessionFilters.d.ts +102 -0
- package/dist/types/nodefony/src/session/storage/sessionSort.d.ts +45 -0
- package/docs/cookies.md +365 -0
- package/docs/index.md +163 -0
- package/docs/observabilite.md +460 -0
- package/docs/rate-limit.md +372 -0
- package/docs/servers.md +935 -0
- package/docs/session.md +768 -0
- package/docs/upload.md +460 -0
- package/package.json +101 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import HttpError from "../../errors/httpError.js";
|
|
2
|
+
import Cookie from "../../cookies/cookie.js";
|
|
3
|
+
import Context from "../Context.js";
|
|
4
|
+
import { sanitizeRequestId } from "../requestId.js";
|
|
5
|
+
import HttpRequest from "./Request.js";
|
|
6
|
+
import HttpResponse from "./Response.js";
|
|
7
|
+
import Http2Request from "../http2/Request.js";
|
|
8
|
+
import Http2Response from "../http2/Response.js";
|
|
9
|
+
import { extend, typeOf } from "nodefony";
|
|
10
|
+
import url, { URL } from "node:url";
|
|
11
|
+
//#region nodefony/src/context/http/HttpContext.ts
|
|
12
|
+
const socketActiveContext = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
const socketTimeoutArmed = /* @__PURE__ */ new WeakSet();
|
|
14
|
+
const PERF_PROBE_SUB = process.env.NF_PERF_PROBE === "1";
|
|
15
|
+
var HttpContext = class extends Context {
|
|
16
|
+
proxy = null;
|
|
17
|
+
isRedirect = false;
|
|
18
|
+
sended = false;
|
|
19
|
+
request;
|
|
20
|
+
response;
|
|
21
|
+
uploadService;
|
|
22
|
+
csrf;
|
|
23
|
+
constructor(container, request, response, type) {
|
|
24
|
+
super(container, type);
|
|
25
|
+
this.uploadService = this.get("upload");
|
|
26
|
+
const perfSub = PERF_PROBE_SUB ? globalThis.__nfPerfProbe : void 0;
|
|
27
|
+
if (perfSub && perfSub.t0 !== 0n) perfSub.uploadNs += Number(process.hrtime.bigint() - perfSub.t0);
|
|
28
|
+
if (this.type === "http2") {
|
|
29
|
+
this.request = new Http2Request(request, this);
|
|
30
|
+
this.response = new Http2Response(response, this);
|
|
31
|
+
} else {
|
|
32
|
+
this.request = new HttpRequest(request, this);
|
|
33
|
+
this.response = new HttpResponse(response, this);
|
|
34
|
+
}
|
|
35
|
+
if (perfSub && perfSub.t0 !== 0n) perfSub.reqResNs += Number(process.hrtime.bigint() - perfSub.t0);
|
|
36
|
+
this.url = this.request.href;
|
|
37
|
+
this.scheme = this.setScheme();
|
|
38
|
+
this.method = this.request.getMethod();
|
|
39
|
+
this.remoteAddress = this.request.remoteAddress;
|
|
40
|
+
this.proxy = null;
|
|
41
|
+
const fwd = this.request.forwarded;
|
|
42
|
+
if (fwd) {
|
|
43
|
+
this.proxy = {
|
|
44
|
+
proxyServer: request.headers["x-forwarded-server"] || "unknown",
|
|
45
|
+
proxyProto: fwd.proto ?? request.headers["x-forwarded-proto"],
|
|
46
|
+
proxyScheme: request.headers["x-forwarded-scheme"],
|
|
47
|
+
proxyPort: request.headers["x-forwarded-port"],
|
|
48
|
+
proxyFor: fwd.forwardedFor ?? request.headers["x-forwarded-for"],
|
|
49
|
+
proxyHost: fwd.host ?? request.headers["x-forwarded-host"],
|
|
50
|
+
proxyUri: request.headers["x-original-uri"],
|
|
51
|
+
proxyRealIp: request.headers["x-real-ip"],
|
|
52
|
+
proxyVia: request.headers.via || "unknown"
|
|
53
|
+
};
|
|
54
|
+
this.log(`PROXY REQUEST ${fwd.fromStandard ? "Forwarded (RFC 7239)" : "x-forwarded"} VIA : ${this.proxy.proxyVia}`, "DEBUG");
|
|
55
|
+
}
|
|
56
|
+
const incomingId = sanitizeRequestId(request.headers["x-request-id"]);
|
|
57
|
+
if (incomingId) this.requestId = incomingId;
|
|
58
|
+
this.domain = this.getHostName();
|
|
59
|
+
this.validDomain = this.isValidDomain();
|
|
60
|
+
this.parseCookies();
|
|
61
|
+
this.cookieSession = this.getCookieSession(this.getSessionCookieName());
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* URL d'origine effective, construite À LA DEMANDE (1ʳᵉ lecture, puis
|
|
65
|
+
* mémoïsée). `Origin` invalide ou `null` (RFC 6454) → repli sur l'URL de la
|
|
66
|
+
* requête, comme le WS — jamais de throw.
|
|
67
|
+
*/
|
|
68
|
+
get originUrl() {
|
|
69
|
+
if (this._originUrl === null) try {
|
|
70
|
+
this._originUrl = new URL(this.request.origin || this.url);
|
|
71
|
+
} catch {
|
|
72
|
+
this._originUrl = new URL(this.url);
|
|
73
|
+
}
|
|
74
|
+
return this._originUrl;
|
|
75
|
+
}
|
|
76
|
+
set originUrl(value) {
|
|
77
|
+
this._originUrl = value;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Chemin timeout direct — appelé par les handlers socket/stream de
|
|
81
|
+
* `setTimeout()`. T4 : remplace l'ancien `once("onTimeout")` posé au ctor
|
|
82
|
+
* (1 onceWrapper node + 1 closure alloués à CHAQUE requête pour un event
|
|
83
|
+
* qui ne fire presque jamais). L'event `onTimeout` reste émis pour
|
|
84
|
+
* d'éventuels listeners externes — guard 0-listener : 0 alloc sinon.
|
|
85
|
+
*/
|
|
86
|
+
_onTimeout() {
|
|
87
|
+
if (this.listenerCount("onTimeout")) this.fire("onTimeout", this);
|
|
88
|
+
this._abortIfPending("Request timeout");
|
|
89
|
+
let error = null;
|
|
90
|
+
if (this.response.stream) error = new HttpError("Gateway Timeout", 504, this);
|
|
91
|
+
else error = new HttpError("Request Timeout", 408, this);
|
|
92
|
+
this.httpKernel?.onError(error, this);
|
|
93
|
+
}
|
|
94
|
+
setScheme() {
|
|
95
|
+
const req = this.request;
|
|
96
|
+
if (req.hasParsedUrl) return req.url.protocol.replace(":", "");
|
|
97
|
+
return req.scheme;
|
|
98
|
+
}
|
|
99
|
+
async handle() {
|
|
100
|
+
this.setTimeout();
|
|
101
|
+
if (this.isRedirect) {
|
|
102
|
+
await this.send();
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
this.fire("onRequest", this);
|
|
106
|
+
this.kernel?.fire("onRequest", this);
|
|
107
|
+
if (!this.resolver && this.router) this.resolver = this.router.resolve(this);
|
|
108
|
+
if (this.resolver && this.resolver.resolve) {
|
|
109
|
+
this.setMetaData();
|
|
110
|
+
return await this.resolver.callController();
|
|
111
|
+
}
|
|
112
|
+
throw new HttpError("", 404, this);
|
|
113
|
+
}
|
|
114
|
+
setTimeout() {
|
|
115
|
+
const res = this.response.response;
|
|
116
|
+
if (!res) return;
|
|
117
|
+
if (this.response.stream) {
|
|
118
|
+
res.setTimeout(this.response.timeout, () => {
|
|
119
|
+
if (!this.response?.response?.writableEnded) this._onTimeout();
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const socket = res.socket;
|
|
124
|
+
if (!socket) return;
|
|
125
|
+
socketActiveContext.set(socket, this);
|
|
126
|
+
const ms = this.response.timeout;
|
|
127
|
+
if (socket.timeout !== ms) socket.setTimeout(ms);
|
|
128
|
+
if (!socketTimeoutArmed.has(socket)) {
|
|
129
|
+
socketTimeoutArmed.add(socket);
|
|
130
|
+
socket.on("timeout", () => {
|
|
131
|
+
const ctx = socketActiveContext.get(socket);
|
|
132
|
+
if (ctx && !ctx.response?.response?.writableEnded) ctx._onTimeout();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async render(chunk, encoding, status, headers) {
|
|
137
|
+
let data = chunk;
|
|
138
|
+
switch (true) {
|
|
139
|
+
case this.isJson:
|
|
140
|
+
data = JSON.stringify(chunk);
|
|
141
|
+
break;
|
|
142
|
+
case this.isHtml:
|
|
143
|
+
default: switch (typeOf(chunk)) {
|
|
144
|
+
case "object":
|
|
145
|
+
this.setContextJson();
|
|
146
|
+
data = JSON.stringify(chunk);
|
|
147
|
+
break;
|
|
148
|
+
case "string":
|
|
149
|
+
if (this.response.contentType === "application/octet-stream") this.setContextHtml();
|
|
150
|
+
break;
|
|
151
|
+
default: if (this.response.contentType === "application/octet-stream") this.response.setContentType("text");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (headers) this.response.setHeaders(headers);
|
|
155
|
+
if (status) this.response.setStatusCode(status);
|
|
156
|
+
return this.send(data, encoding);
|
|
157
|
+
}
|
|
158
|
+
async end() {
|
|
159
|
+
return this.saveSession().then(async (_session) => {
|
|
160
|
+
return this.close().catch((e) => {
|
|
161
|
+
throw e;
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async send(chunk, encoding) {
|
|
166
|
+
if (this.finished && !this.sended) {
|
|
167
|
+
this.log("send() on finished context — client disconnected", "DEBUG");
|
|
168
|
+
return this.response;
|
|
169
|
+
}
|
|
170
|
+
if (this.sended || this.finished || this.response.isHeaderSent()) return new Promise((_resolve, reject) => {
|
|
171
|
+
return reject(/* @__PURE__ */ new Error("Response Already sended"));
|
|
172
|
+
});
|
|
173
|
+
if (!this.timingEnabled) return this.#doSend(chunk, encoding);
|
|
174
|
+
this.phaseStart("send");
|
|
175
|
+
try {
|
|
176
|
+
return await this.#doSend(chunk, encoding);
|
|
177
|
+
} finally {
|
|
178
|
+
this.phaseEnd("send");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async #doSend(chunk, encoding) {
|
|
182
|
+
try {
|
|
183
|
+
if (this.session != null) await this.saveSession();
|
|
184
|
+
if (chunk) this.response?.setBody(chunk);
|
|
185
|
+
if (this.listenerCount("onSend") > 0) await this.fireAsync("onSend", this.response, this);
|
|
186
|
+
try {
|
|
187
|
+
this.writeHead();
|
|
188
|
+
} catch (e) {
|
|
189
|
+
this.log(e, "WARNING");
|
|
190
|
+
}
|
|
191
|
+
if (this.isRedirect) return await this.close();
|
|
192
|
+
return await this.write(chunk, encoding);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
this.log(error, "ERROR");
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
writeHead(statusCode, headers) {
|
|
199
|
+
if (this.response) {
|
|
200
|
+
if (this.csrfToken) this.setCookie(new Cookie("csrf-token", this.csrfToken, {
|
|
201
|
+
httpOnly: false,
|
|
202
|
+
sameSite: "Strict",
|
|
203
|
+
secure: this.scheme === "https",
|
|
204
|
+
path: "/"
|
|
205
|
+
}));
|
|
206
|
+
this.response.setCookies();
|
|
207
|
+
this.response.writeHead(statusCode, headers);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async write(chunk, encoding, _flush = false) {
|
|
211
|
+
await this.response.send(chunk, encoding || this.response.encoding).then(() => {
|
|
212
|
+
this.sended = true;
|
|
213
|
+
}).catch((e) => {
|
|
214
|
+
throw e;
|
|
215
|
+
});
|
|
216
|
+
return this.close().catch((e) => {
|
|
217
|
+
throw e;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
flush(chunk, encoding) {
|
|
221
|
+
return this.response.flush(chunk, encoding);
|
|
222
|
+
}
|
|
223
|
+
async close() {
|
|
224
|
+
if (this.listenerCount("onClose") > 0) await this.fireAsync("onClose", this);
|
|
225
|
+
return this.response.end().then(() => this.response).catch((e) => {
|
|
226
|
+
throw e;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
redirect(Url, status, headers) {
|
|
230
|
+
if (typeof Url === "object") return this.response.redirect(url.format(Url), status, headers);
|
|
231
|
+
return this.response.redirect(Url, status, headers);
|
|
232
|
+
}
|
|
233
|
+
redirectHttps(status, headers) {
|
|
234
|
+
if (this.session) {}
|
|
235
|
+
let urlExtend = null;
|
|
236
|
+
if (this.proxy) urlExtend = {
|
|
237
|
+
protocol: "https",
|
|
238
|
+
href: "",
|
|
239
|
+
host: ""
|
|
240
|
+
};
|
|
241
|
+
else urlExtend = {
|
|
242
|
+
protocol: "https",
|
|
243
|
+
port: this.httpKernel?.httpsPort || 443,
|
|
244
|
+
href: "",
|
|
245
|
+
host: ""
|
|
246
|
+
};
|
|
247
|
+
const urlChange = extend({}, this.request.url, urlExtend);
|
|
248
|
+
const newUrl = url.format(urlChange);
|
|
249
|
+
return this.redirect(newUrl, status, headers);
|
|
250
|
+
}
|
|
251
|
+
redirectHttp(status, headers) {
|
|
252
|
+
if (this.session) {}
|
|
253
|
+
let urlExtend = null;
|
|
254
|
+
if (this.proxy) urlExtend = {
|
|
255
|
+
protocol: "http",
|
|
256
|
+
href: "",
|
|
257
|
+
host: ""
|
|
258
|
+
};
|
|
259
|
+
else urlExtend = {
|
|
260
|
+
protocol: "http",
|
|
261
|
+
port: this.httpKernel?.httpPort || 80,
|
|
262
|
+
href: "",
|
|
263
|
+
host: ""
|
|
264
|
+
};
|
|
265
|
+
const urlChange = extend({}, this.request.url, urlExtend);
|
|
266
|
+
const newUrl = url.format(urlChange);
|
|
267
|
+
return this.redirect(newUrl, status, headers);
|
|
268
|
+
}
|
|
269
|
+
getHostName() {
|
|
270
|
+
return this.request?.getHostName();
|
|
271
|
+
}
|
|
272
|
+
getRemoteAddress() {
|
|
273
|
+
return this.request?.getRemoteAddress();
|
|
274
|
+
}
|
|
275
|
+
getHost() {
|
|
276
|
+
return this.request?.getHost();
|
|
277
|
+
}
|
|
278
|
+
getUserAgent() {
|
|
279
|
+
return this.request?.getUserAgent();
|
|
280
|
+
}
|
|
281
|
+
getMethod() {
|
|
282
|
+
return this.request?.getMethod();
|
|
283
|
+
}
|
|
284
|
+
setContentType(type, encoding) {
|
|
285
|
+
return this.response.setContentType(type, encoding);
|
|
286
|
+
}
|
|
287
|
+
resolveIsHtml() {
|
|
288
|
+
return this.request?.acceptHtml ?? false;
|
|
289
|
+
}
|
|
290
|
+
setDefaultContentType() {
|
|
291
|
+
if (this.isHtml) this.response.setContentType("html", "utf-8");
|
|
292
|
+
else if (this.request.accepts("json")) {
|
|
293
|
+
this.isJson = true;
|
|
294
|
+
this.response.setContentType("json", "utf-8");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
setContextJson(encoding = "utf-8") {
|
|
298
|
+
this.isJson = true;
|
|
299
|
+
this.isHtml = false;
|
|
300
|
+
this.response.setContentType("json", encoding);
|
|
301
|
+
}
|
|
302
|
+
setContextHtml(encoding = "utf-8") {
|
|
303
|
+
this.isHtml = true;
|
|
304
|
+
this.isJson = false;
|
|
305
|
+
this.response.setContentType("html", encoding);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
//#endregion
|
|
309
|
+
export { HttpContext as default };
|