1 | function buildRequest(method, url) {
|
2 | return {
|
3 | method,
|
4 | path: url,
|
5 | redirect: this.options.followRedirects ? 'follow' : 'manual',
|
6 | headers: {},
|
7 | setHeader(name, value) {
|
8 | this.headers[name.toLowerCase()] = value;
|
9 | },
|
10 | getHeader(name) {
|
11 | return this.headers[name.toLowerCase()];
|
12 | },
|
13 | getHeaders() {
|
14 | return this.headers;
|
15 | },
|
16 | };
|
17 | }
|
18 |
|
19 | function finalizeRequest() {
|
20 | this._finalizeRequest();
|
21 | if (this.data) this.request.body = this.data;
|
22 | return window.fetch(this.request.path, this.request)
|
23 | .then((r) => r.text().then((t) => {
|
24 | const headers = {};
|
25 | for (const [k, v] of r.headers.entries()) headers[k.toLowerCase()] = v;
|
26 | return { response: r, raw: t, headers };
|
27 | }));
|
28 | }
|
29 |
|
30 | module.exports = {
|
31 | buildRequest, finalizeRequest,
|
32 | shouldSendRaw: () => false,
|
33 | METHODS: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH'],
|
34 | STATUS_CODES: {},
|
35 | Extension: Object,
|
36 | FormData: window.FormData,
|
37 | };
|