(exchange: CopilotRequestExchange)
| 644 | ]); |
| 645 | |
| 646 | async function buildFetchRequest(exchange: CopilotRequestExchange): Promise<Request> { |
| 647 | const headers = new Headers(); |
| 648 | for (const [name, values] of Object.entries(exchange.headers)) { |
| 649 | if (!values) { |
| 650 | continue; |
| 651 | } |
| 652 | if (FORBIDDEN_REQUEST_HEADERS.has(name.toLowerCase())) { |
| 653 | continue; |
| 654 | } |
| 655 | for (const value of values) { |
| 656 | headers.append(name, value); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | const method = exchange.method.toUpperCase(); |
| 661 | const hasBody = method !== "GET" && method !== "HEAD"; |
| 662 | |
| 663 | let body: Uint8Array | undefined; |
| 664 | if (hasBody) { |
| 665 | const buffered = await drainAsync(exchange.requestBody); |
| 666 | if (buffered.length > 0) { |
| 667 | body = buffered; |
| 668 | } |
| 669 | } else { |
| 670 | await drainAsync(exchange.requestBody); |
| 671 | } |
| 672 | |
| 673 | return new Request(exchange.url, { method, headers, body }); |
| 674 | } |
| 675 | |
| 676 | async function drainAsync(stream: AsyncIterable<Uint8Array>): Promise<Uint8Array> { |
| 677 | const parts: Uint8Array[] = []; |
no test coverage detected
searching dependent graphs…