| 42 | } |
| 43 | |
| 44 | function echoWebSocket(request: HttpServerRequest.HttpServerRequest) { |
| 45 | return Effect.gen(function* () { |
| 46 | const socket = yield* Effect.orDie(request.upgrade) |
| 47 | const write = yield* socket.writer |
| 48 | // The upstream announces the negotiated protocol, then echoes every |
| 49 | // received frame. The assertions use those messages to prove proxy flow. |
| 50 | yield* socket |
| 51 | .runRaw((message) => write(`echo:${String(message)}`), { |
| 52 | onOpen: write(`protocol:${request.headers["sec-websocket-protocol"] ?? "none"}`).pipe( |
| 53 | Effect.catch(() => Effect.void), |
| 54 | ), |
| 55 | }) |
| 56 | .pipe(Effect.catch(() => Effect.void)) |
| 57 | return HttpServerResponse.empty() |
| 58 | }) |
| 59 | } |
| 60 | |
| 61 | describe("HttpApi workspace proxy", () => { |
| 62 | it.live("proxies HTTP request and returns streamed response with status and headers", () => |