1/**
2 * Accessors for the Node.js objects behind an Effect HTTP server request.
3 *
4 * `toIncomingMessage` returns the underlying Node `http.IncomingMessage`.
5 * `toServerResponse` returns the underlying Node `http.ServerResponse`,
6 * evaluating the stored response thunk when the response was created lazily.
7 *
8 * @since 4.0.0
9 */
10import type { HttpServerRequest } from "effect/http/HttpServerRequest"
11import type * as Http from "node:http"
12
13/**
14 * Returns the underlying Node `IncomingMessage` for a platform Node
15 * `HttpServerRequest`.
16 *
17 * @category accessors
18 * @since 4.0.0
19 */
20export const toIncomingMessage = (self: HttpServerRequest): Http.IncomingMessage => self.source as any
21
22/**
23 * Returns the underlying Node `ServerResponse` for a platform Node
24 * `HttpServerRequest`, evaluating the stored response thunk when the response
25 * was created lazily.
26 *
27 * @category accessors
28 * @since 4.0.0
29 */
30export const toServerResponse = (self: HttpServerRequest): Http.ServerResponse => {
31 const res = (self as any).response
32 return typeof res === "function" ? res() : res
33}