| 1375 | * @since 4.0.0 |
| 1376 | */ |
| 1377 | export const fromWeb = (response: Response): HttpServerResponse => { |
| 1378 | const headers = new globalThis.Headers(response.headers) |
| 1379 | const setCookieHeaders = headers.getSetCookie() |
| 1380 | headers.delete("set-cookie") |
| 1381 | let self = empty({ |
| 1382 | status: response.status, |
| 1383 | statusText: response.statusText, |
| 1384 | headers: headers as any, |
| 1385 | cookies: Cookies.fromSetCookie(setCookieHeaders) |
| 1386 | }) |
| 1387 | if (response.body) { |
| 1388 | const contentType = response.headers.get("content-type") |
| 1389 | self = setBody( |
| 1390 | self, |
| 1391 | Body.stream( |
| 1392 | Stream.fromReadableStream({ |
| 1393 | evaluate: () => response.body!, |
| 1394 | onError: (e) => e |
| 1395 | }), |
| 1396 | contentType ?? undefined |
| 1397 | ) |
| 1398 | ) |
| 1399 | } |
| 1400 | return self |
| 1401 | } |