1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 07:41:56 +00:00
musix-oss/node_modules/snekfetch/src/browser.js
MatteZ02 5eb0264906 fix
2019-05-30 12:06:47 +03:00

37 lines
939 B
JavaScript

function buildRequest(method, url) {
return {
method,
path: url,
redirect: this.options.followRedirects ? 'follow' : 'manual',
headers: {},
setHeader(name, value) {
this.headers[name.toLowerCase()] = value;
},
getHeader(name) {
return this.headers[name.toLowerCase()];
},
};
}
function finalizeRequest() {
this._finalizeRequest();
if (this.data)
this.request.body = this.data;
return window.fetch(this.request.path, this.request)
.then((r) => r.text().then((t) => {
const headers = {};
for (const [k, v] of r.headers.entries())
headers[k.toLowerCase()] = v;
return { response: r, raw: t, headers };
}));
}
module.exports = {
buildRequest, finalizeRequest,
shouldSendRaw: () => false,
METHODS: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH'],
STATUS_CODES: {},
Extension: Object,
FormData: window.FormData,
};