| 2680 | |
| 2681 | // Sends the requests pipelined on one connection and returns everything received until the connection closes. |
| 2682 | const rawGet = (port: number, paths: ReadonlyArray<string>, method = "GET") => |
| 2683 | Effect.callback<string>((resume) => { |
| 2684 | const socket = Net.connect({ port, host: "127.0.0.1" }, () => { |
| 2685 | socket.write( |
| 2686 | paths.map((path, index) => |
| 2687 | `${method} ${path} HTTP/1.1\r\nHost: 127.0.0.1\r\n${ |
| 2688 | index === paths.length - 1 ? "Connection: close\r\n" : "" |
| 2689 | }\r\n` |
| 2690 | ).join("") |
| 2691 | ) |
| 2692 | }) |
| 2693 | let received = "" |
| 2694 | socket.setEncoding("latin1") |
| 2695 | socket.on("data", (chunk) => received += chunk) |
| 2696 | socket.on("error", constVoid) |
| 2697 | socket.on("close", () => resume(Effect.succeed(received))) |
| 2698 | return Effect.sync(() => socket.destroy()) |
| 2699 | }).pipe(Effect.timeout("2 seconds")) |
| 2700 | |
| 2701 | interface WebSocketFrame { |
| 2702 | readonly opcode: number |