ethers.js/packages/web/lib.esm/browser-geturl.js

48 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2020-04-18 05:14:55 -04:00
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
2020-07-30 17:04:53 -04:00
import { arrayify } from "@ethersproject/bytes";
2020-04-18 05:14:55 -04:00
export function getUrl(href, options) {
return __awaiter(this, void 0, void 0, function* () {
if (options == null) {
options = {};
}
const request = {
method: (options.method || "GET"),
headers: (options.headers || {}),
body: (options.body || undefined),
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
redirect: "follow",
referrer: "client",
};
const response = yield fetch(href, request);
2020-07-30 17:04:53 -04:00
const body = yield response.arrayBuffer();
2020-04-18 05:14:55 -04:00
const headers = {};
if (response.headers.forEach) {
response.headers.forEach((value, key) => {
headers[key.toLowerCase()] = value;
});
}
else {
((response.headers).keys)().forEach((key) => {
headers[key.toLowerCase()] = response.headers.get(key);
});
}
return {
headers: headers,
statusCode: response.status,
statusMessage: response.statusText,
2020-07-30 17:04:53 -04:00
body: arrayify(new Uint8Array(body)),
2020-04-18 05:14:55 -04:00
};
});
}
2020-07-13 08:03:56 -04:00
//# sourceMappingURL=browser-geturl.js.map