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

Class ServerRequestImpl

packages/platform-bun/src/internal/httpServer.ts:216–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpServerRequest {
217 readonly [ServerRequest.TypeId]: ServerRequest.TypeId
218 readonly [IncomingMessage.TypeId]: IncomingMessage.TypeId
219 constructor(
220 readonly source: Request,
221 public resolve: (response: Response) => void,
222 readonly url: string,
223 private bunServer: BunServer,
224 public headersOverride?: Headers.Headers,
225 private remoteAddressOverride?: string
226 ) {
227 super()
228 this[ServerRequest.TypeId] = ServerRequest.TypeId
229 this[IncomingMessage.TypeId] = IncomingMessage.TypeId
230 }
231 toJSON(): unknown {
232 return IncomingMessage.inspect(this, {
233 _id: "@effect/platform/HttpServerRequest",
234 method: this.method,
235 url: this.originalUrl
236 })
237 }
238 modify(
239 options: {
240 readonly url?: string | undefined
241 readonly headers?: Headers.Headers | undefined
242 readonly remoteAddress?: string | undefined
243 }
244 ) {
245 return new ServerRequestImpl(
246 this.source,
247 this.resolve,
248 options.url ?? this.url,
249 this.bunServer,
250 options.headers ?? this.headersOverride,
251 options.remoteAddress ?? this.remoteAddressOverride
252 )
253 }
254 get method(): HttpMethod {
255 return this.source.method.toUpperCase() as HttpMethod
256 }
257 get originalUrl() {
258 return this.source.url
259 }
260 get remoteAddress(): Option.Option<string> {
261 return this.remoteAddressOverride
262 ? Option.some(this.remoteAddressOverride)
263 : Option.fromNullable(this.bunServer.requestIP(this.source)?.address)
264 }
265 get headers(): Headers.Headers {
266 this.headersOverride ??= Headers.fromInput(this.source.headers)
267 return this.headersOverride
268 }
269
270 private cachedCookies: ReadonlyRecord<string, string> | undefined
271 get cookies() {
272 if (this.cachedCookies) {
273 return this.cachedCookies

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…