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

Class ServerRequestImpl

packages/platform/node/src/NodeHttpServer.ts:644–853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

642const bodyBytesRead = new WeakMap<Http.IncomingMessage, number>()
643
644class ServerRequestImpl extends NodeHttpIncomingMessage<HttpServerError> implements HttpServerRequest {
645 protected override readonly destroyOnOverflow = false
646 // The adapter tears the body down after the response instead.
647 protected override readonly closeOnDone = false
648 readonly [Request.TypeId]: typeof Request.TypeId
649 readonly response: Http.ServerResponse | LazyArg<Http.ServerResponse>
650 private upgradeState?: UpgradeState | undefined
651 readonly url: string
652 private headersOverride?: Headers.Headers | undefined
653 private peerAddressOverride?: Option.Option<string> | undefined
654 readonly protocol: "http" | "https" | undefined
655
656 constructor(
657 source: Http.IncomingMessage,
658 response: Http.ServerResponse | LazyArg<Http.ServerResponse>,
659 upgradeState?: UpgradeState,
660 url?: string,
661 headersOverride?: Headers.Headers,
662 remoteAddressOverride?: Option.Option<string>,
663 peerAddressOverride?: Option.Option<string>,
664 protocol?: "http" | "https"
665 ) {
666 super(source, (cause) =>
667 new HttpServerError({
668 reason: new RequestParseError({
669 request: this,
670 reason: cause instanceof NodeStream.MaxBytesError ? "BodyTooLarge" : "Parse",
671 cause
672 })
673 }), remoteAddressOverride)
674 this[Request.TypeId] = Request.TypeId
675 this.response = response
676 this.upgradeState = upgradeState
677 if (url === undefined) {
678 const target = absoluteTarget(source.url!)
679 if (target === undefined) {
680 url = source.url!
681 } else {
682 // RFC 9112 §3.2.2: the request-target authority takes precedence over Host.
683 url = target.pathname + target.search
684 const headers: Http.IncomingHttpHeaders = { ...requestHeaders(source), host: target.host }
685 headersOverride = Headers.fromInput(headers)
686 }
687 }
688 this.url = url
689 this.headersOverride = headersOverride
690 this.peerAddressOverride = peerAddressOverride
691 this.protocol = protocol
692 }
693
694 get peerAddress(): Option.Option<string> {
695 return this.peerAddressOverride ?? this.remoteAddress
696 }
697
698 private cachedCookies: Record.ReadonlyRecord<string, string> | undefined
699 get cookies() {
700 if (this.cachedCookies) {
701 return this.cachedCookies

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected