MCPcopy Create free account
hub / github.com/Effect-TS/effect / ServerRequestImpl

Class ServerRequestImpl

packages/platform-node/src/internal/httpServer.ts:220–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220class ServerRequestImpl extends HttpIncomingMessageImpl<Error.RequestError> implements ServerRequest.HttpServerRequest {
221 readonly [ServerRequest.TypeId]: ServerRequest.TypeId
222
223 constructor(
224 readonly source: Http.IncomingMessage,
225 readonly response: Http.ServerResponse | LazyArg<Http.ServerResponse>,
226 private upgradeEffect?: Effect.Effect<Socket.Socket, Error.RequestError>,
227 readonly url = source.url!,
228 private headersOverride?: Headers.Headers,
229 remoteAddressOverride?: string
230 ) {
231 super(source, (cause) =>
232 new Error.RequestError({
233 request: this,
234 reason: "Decode",
235 cause
236 }), remoteAddressOverride)
237 this[ServerRequest.TypeId] = ServerRequest.TypeId
238 }
239
240 private cachedCookies: ReadonlyRecord<string, string> | undefined
241 get cookies() {
242 if (this.cachedCookies) {
243 return this.cachedCookies
244 }
245 return this.cachedCookies = Cookies.parseHeader(this.headers.cookie ?? "")
246 }
247
248 get resolvedResponse(): Http.ServerResponse {
249 return typeof this.response === "function" ? this.response() : this.response
250 }
251
252 modify(
253 options: {
254 readonly url?: string | undefined
255 readonly headers?: Headers.Headers | undefined
256 readonly remoteAddress?: string | undefined
257 }
258 ) {
259 return new ServerRequestImpl(
260 this.source,
261 this.response,
262 this.upgradeEffect,
263 options.url ?? this.url,
264 options.headers ?? this.headersOverride,
265 options.remoteAddress ?? this.remoteAddressOverride
266 )
267 }
268
269 get originalUrl(): string {
270 return this.source.url!
271 }
272
273 get method(): HttpMethod {
274 return this.source.method!.toUpperCase() as HttpMethod
275 }
276
277 get headers(): Headers.Headers {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected