MCPcopy
hub / github.com/Effect-TS/effect / ServerRequestImpl

Class ServerRequestImpl

packages/platform/src/internal/httpServerRequest.ts:188–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpServerRequest {
189 readonly [TypeId]: ServerRequest.TypeId
190 readonly [IncomingMessage.TypeId]: IncomingMessage.TypeId
191 constructor(
192 readonly source: Request,
193 readonly url: string,
194 public headersOverride?: Headers.Headers,
195 private remoteAddressOverride?: string
196 ) {
197 super()
198 this[TypeId] = TypeId
199 this[IncomingMessage.TypeId] = IncomingMessage.TypeId
200 }
201 toJSON(): unknown {
202 return IncomingMessage.inspect(this, {
203 _id: "@effect/platform/HttpServerRequest",
204 method: this.method,
205 url: this.originalUrl
206 })
207 }
208 modify(
209 options: {
210 readonly url?: string | undefined
211 readonly headers?: Headers.Headers | undefined
212 readonly remoteAddress?: string | undefined
213 }
214 ) {
215 return new ServerRequestImpl(
216 this.source,
217 options.url ?? this.url,
218 options.headers ?? this.headersOverride,
219 options.remoteAddress ?? this.remoteAddressOverride
220 )
221 }
222 get method(): HttpMethod {
223 return this.source.method.toUpperCase() as HttpMethod
224 }
225 get originalUrl() {
226 return this.source.url
227 }
228 get remoteAddress(): Option.Option<string> {
229 return this.remoteAddressOverride ? Option.some(this.remoteAddressOverride) : Option.none()
230 }
231 get headers(): Headers.Headers {
232 this.headersOverride ??= Headers.fromInput(this.source.headers as any)
233 return this.headersOverride
234 }
235
236 private cachedCookies: ReadonlyRecord<string, string> | undefined
237 get cookies() {
238 if (this.cachedCookies) {
239 return this.cachedCookies
240 }
241 return this.cachedCookies = Cookies.parseHeader(this.headers.cookie ?? "")
242 }
243
244 get stream(): Stream.Stream<Uint8Array, Error.RequestError> {
245 return this.source.body

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected