"use strict"; export type GetUrlResponse = { statusCode: number, statusMessage: string; headers: { [ key: string] : string }; body: string; }; export type Options = { method?: string, body?: string headers?: { [ key: string] : string }, }; export async function getUrl(href: string, options?: Options): Promise { if (options == null) { options = { }; } const request = { method: (options.method || "GET"), headers: (options.headers || { }), body: (options.body || undefined), mode: "cors", // no-cors, cors, *same-origin cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached credentials: "same-origin", // include, *same-origin, omit redirect: "follow", // manual, *follow, error referrer: "client", // no-referrer, *client }; const response = await fetch(href, request); const body = await response.text(); const headers: { [ name: string ]: string } = { }; if (response.headers.forEach) { response.headers.forEach((value, key) => { headers[key.toLowerCase()] = value; }); } else { (<() => Array>(((response.headers)).keys))().forEach((key) => { headers[key.toLowerCase()] = response.headers.get(key); }); } return { headers: headers, statusCode: response.status, statusMessage: response.statusText, body: body, } }