| 779 | } |
| 780 | |
| 781 | async function toFetchRequest(req: IncomingMessage): Promise<Request> { |
| 782 | const body = await readBody(req) |
| 783 | const host = |
| 784 | typeof req.headers.host === `string` ? req.headers.host : `localhost` |
| 785 | const url = new URL(req.url ?? `/`, `http://${host}`) |
| 786 | const headers = new Headers() |
| 787 | |
| 788 | for (const [name, value] of Object.entries(req.headers)) { |
| 789 | if (Array.isArray(value)) { |
| 790 | for (const item of value) { |
| 791 | headers.append(name, item) |
| 792 | } |
| 793 | continue |
| 794 | } |
| 795 | if (value === undefined) continue |
| 796 | headers.set(name, value) |
| 797 | } |
| 798 | |
| 799 | return new Request(url, { |
| 800 | method: req.method, |
| 801 | headers, |
| 802 | body: body.length > 0 ? Buffer.from(body) : undefined, |
| 803 | }) |
| 804 | } |
| 805 | |
| 806 | async function sendNodeResponse( |
| 807 | res: ServerResponse, |