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

Class ServerRequestImpl

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected