| 88 | |
| 89 | let clients; |
| 90 | function fetchClientRequest(url, options) { |
| 91 | clients ??= new Map; |
| 92 | let origin = url.origin; |
| 93 | let client = clients.get(origin); |
| 94 | if (!client) { |
| 95 | const protocol = url.protocol; |
| 96 | const host = url.hostname; |
| 97 | if (protocol == "http:") { |
| 98 | const port = url.port || 80; |
| 99 | client = new device.network.http.io({ |
| 100 | ...device.network.http, |
| 101 | host, |
| 102 | port, |
| 103 | onError() { |
| 104 | clients.delete(origin); |
| 105 | this.close(); |
| 106 | } |
| 107 | }); |
| 108 | } |
| 109 | else { |
| 110 | const port = url.port || 443; |
| 111 | client = new device.network.https.io({ |
| 112 | ...device.network.https, |
| 113 | host, |
| 114 | port, |
| 115 | onError() { |
| 116 | clients.delete(origin); |
| 117 | this.close(); |
| 118 | } |
| 119 | }); |
| 120 | } |
| 121 | clients.set(origin, client); |
| 122 | } |
| 123 | let path = url.pathname; |
| 124 | let query = url.search; |
| 125 | if (query) |
| 126 | path += query; |
| 127 | options.path = path; |
| 128 | client.request(options); |
| 129 | } |
| 130 | |
| 131 | function fetch(href, info = {}) { |
| 132 | return new Promise((resolveResponse, rejectResponse) => { |