1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 10:51:56 +00:00
musix-oss/node_modules/snekfetch/src/browser.js

37 lines
939 B
JavaScript
Raw Normal View History

2019-05-30 09:06:47 +00:00
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,
};