Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/core/cri/deno-cri/external-request.js
3587 views
1
/*
2
* external-request.js
3
*
4
* Copyright (c) 2021 Andrea Cardaci <[email protected]>
5
*
6
* Deno port Copyright (C) 2022 Posit Software, PBC
7
*/
8
9
export default async function externalRequest(options) {
10
// perform the DNS lookup manually so that the HTTP host header generated by
11
// http.get will contain the IP address, this is needed because since Chrome
12
// 66 the host header cannot contain an host name different than localhost
13
// (see https://github.com/cyrus-and/chrome-remote-interface/issues/340)
14
/*if (!options.useHostName) {
15
const addresses = await Deno.resolveDns(options.host, "A");
16
options = Object.assign({}, options);
17
options.host = addresses[0];
18
}*/
19
20
const url = `${options.protocol}:/${options.host}:${options.port}${options.path}`;
21
const fetchOpts = {};
22
if (options.method) {
23
fetchOpts.method = options.method;
24
}
25
const response = await fetch(url, options);
26
const text = await response.text();
27
28
if (response.status !== 200) {
29
throw new Error(text);
30
}
31
return text;
32
}
33
34