Path: blob/main/src/core/cri/deno-cri/external-request.js
3587 views
/*1* external-request.js2*3* Copyright (c) 2021 Andrea Cardaci <[email protected]>4*5* Deno port Copyright (C) 2022 Posit Software, PBC6*/78export default async function externalRequest(options) {9// perform the DNS lookup manually so that the HTTP host header generated by10// http.get will contain the IP address, this is needed because since Chrome11// 66 the host header cannot contain an host name different than localhost12// (see https://github.com/cyrus-and/chrome-remote-interface/issues/340)13/*if (!options.useHostName) {14const addresses = await Deno.resolveDns(options.host, "A");15options = Object.assign({}, options);16options.host = addresses[0];17}*/1819const url = `${options.protocol}:/${options.host}:${options.port}${options.path}`;20const fetchOpts = {};21if (options.method) {22fetchOpts.method = options.method;23}24const response = await fetch(url, options);25const text = await response.text();2627if (response.status !== 200) {28throw new Error(text);29}30return text;31}323334