The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** |
| 2 | * Accessors for the Node.js objects behind an Effect HTTP server request. |
| 3 | * |
| 4 | * `toIncomingMessage` returns the underlying Node `http.IncomingMessage`, or |
| 5 | * `http2.Http2ServerRequest` for an HTTP/2 request. `toServerResponse` returns |
| 6 | * the underlying Node `http.ServerResponse` or `http2.Http2ServerResponse`, |
| 7 | * evaluating the stored response thunk when the response was created lazily. |
| 8 | * |
| 9 | * @stability unstable |
| 10 | * @since 4.0.0 |
| 11 | */ |
| 12 | import type { HttpServerRequest } from "effect/http/HttpServerRequest" |
| 13 | import type * as Http from "node:http" |
| 14 | import type * as Http2 from "node:http2" |
| 15 | |
| 16 | /** |
| 17 | * Returns the underlying Node `IncomingMessage` for a platform Node |
| 18 | * `HttpServerRequest`, or the `Http2ServerRequest` when it was received over |
| 19 | * HTTP/2. |
| 20 | * |
| 21 | * @stability unstable |
| 22 | * @category accessors |
| 23 | * @since 4.0.0 |
| 24 | */ |
| 25 | export const toIncomingMessage = (self: HttpServerRequest): Http.IncomingMessage | Http2.Http2ServerRequest => |
| 26 | self.source as any |
| 27 | |
| 28 | /** |
| 29 | * Returns the underlying Node `ServerResponse` for a platform Node |
| 30 | * `HttpServerRequest`, or the `Http2ServerResponse` when it was received over |
| 31 | * HTTP/2, evaluating the stored response thunk when the response was created |
| 32 | * lazily. |
| 33 | * |
| 34 | * @stability unstable |
| 35 | * @category accessors |
| 36 | * @since 4.0.0 |
| 37 | */ |
| 38 | export const toServerResponse = (self: HttpServerRequest): Http.ServerResponse | Http2.Http2ServerResponse => { |
| 39 | const res = (self as any).response |
| 40 | return typeof res === "function" ? res() : res |
| 41 | } |