MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fetchClientRequest

Function fetchClientRequest

examples/io/tcp/fetch/fetch.js:90–129  ·  view source on GitHub ↗
(url, options)

Source from the content-addressed store, hash-verified

88
89let clients;
90function 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
131function fetch(href, info = {}) {
132 return new Promise((resolveResponse, rejectResponse) => {

Callers 2

onDoneFunction · 0.70
fetchFunction · 0.70

Calls 3

getMethod · 0.65
setMethod · 0.65
requestMethod · 0.45

Tested by

no test coverage detected