react-native-nitro-fetch 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NitroFetch.podspec +1 -3
- package/README.md +39 -11
- package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +6 -2
- package/android/src/main/java/com/margelo/nitro/nitrofetch/DevToolsReporterImpl.kt +27 -36
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchClient.kt +45 -0
- package/ios/NitroAutoPrefetcher.swift +4 -0
- package/ios/NitroDevToolsReporter.mm +37 -31
- package/ios/NitroFetchClient.swift +56 -0
- package/lib/module/CurlGenerator.js.map +1 -2
- package/lib/module/Headers.js.map +2 -1
- package/lib/module/HermesProfiler.js.map +2 -1
- package/lib/module/NetworkInspector.js +1 -5
- package/lib/module/NetworkInspector.js.map +2 -1
- package/lib/module/NitroCronet.nitro.js.map +2 -1
- package/lib/module/NitroFetch.nitro.js.map +2 -1
- package/lib/module/NitroInstances.js.map +2 -1
- package/lib/module/Request.js.map +1 -2
- package/lib/module/Response.js.map +2 -2
- package/lib/module/fetch.js +147 -1
- package/lib/module/fetch.js.map +1 -1
- package/lib/module/index.web.js +1 -0
- package/lib/module/index.web.js.map +1 -2
- package/lib/module/tokenRefresh.js.map +1 -2
- package/lib/module/utf8.js.map +1 -2
- package/lib/typescript/src/fetch.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/CurlGenerator.js +26 -23
- package/src/Headers.js +116 -108
- package/src/HermesProfiler.js +18 -16
- package/src/NetworkInspector.js +179 -171
- package/src/NitroInstances.js +1 -2
- package/src/Request.js +164 -167
- package/src/Response.js +242 -244
- package/src/fetch.js +842 -706
- package/src/fetch.ts +170 -1
- package/src/index.js +2 -17
- package/src/index.web.js +67 -69
- package/src/tokenRefresh.js +77 -75
- package/src/utf8.js +27 -28
package/src/Request.js
CHANGED
|
@@ -1,176 +1,173 @@
|
|
|
1
1
|
import { NitroHeaders } from './Headers';
|
|
2
2
|
import { stringToUTF8, utf8ToString } from './utf8';
|
|
3
3
|
export class NitroRequest {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.keepalive = init?.keepalive ?? false;
|
|
89
|
-
this._body = init?.body ?? null;
|
|
4
|
+
url;
|
|
5
|
+
method;
|
|
6
|
+
headers;
|
|
7
|
+
redirect;
|
|
8
|
+
signal;
|
|
9
|
+
cache;
|
|
10
|
+
credentials;
|
|
11
|
+
mode;
|
|
12
|
+
referrer;
|
|
13
|
+
referrerPolicy;
|
|
14
|
+
integrity;
|
|
15
|
+
keepalive;
|
|
16
|
+
destination;
|
|
17
|
+
_body;
|
|
18
|
+
_bodyUsed = false;
|
|
19
|
+
constructor(input, init) {
|
|
20
|
+
if (input instanceof NitroRequest) {
|
|
21
|
+
// Clone from another NitroRequest
|
|
22
|
+
this.url = input.url;
|
|
23
|
+
this.method = (init?.method ?? input.method).toUpperCase();
|
|
24
|
+
this.headers = new NitroHeaders(init?.headers
|
|
25
|
+
? init.headers instanceof NitroHeaders
|
|
26
|
+
? init.headers
|
|
27
|
+
: init.headers
|
|
28
|
+
: input.headers);
|
|
29
|
+
this.redirect = init?.redirect ?? input.redirect;
|
|
30
|
+
this.signal = init?.signal ?? input.signal;
|
|
31
|
+
this.cache = init?.cache ?? input.cache;
|
|
32
|
+
this.credentials = init?.credentials ?? input.credentials;
|
|
33
|
+
this.mode = init?.mode ?? input.mode;
|
|
34
|
+
this.referrer = init?.referrer ?? input.referrer;
|
|
35
|
+
this.referrerPolicy = init?.referrerPolicy ?? input.referrerPolicy;
|
|
36
|
+
this.integrity = init?.integrity ?? input.integrity;
|
|
37
|
+
this.keepalive = init?.keepalive ?? input.keepalive;
|
|
38
|
+
this._body = init?.body !== undefined ? (init.body ?? null) : input._body;
|
|
39
|
+
}
|
|
40
|
+
else if (typeof input === 'object' &&
|
|
41
|
+
input !== null &&
|
|
42
|
+
'url' in input &&
|
|
43
|
+
'method' in input &&
|
|
44
|
+
'headers' in input &&
|
|
45
|
+
!(input instanceof URL)) {
|
|
46
|
+
// Construct from a Request-like object (standard Request or duck-typed)
|
|
47
|
+
this.url = input.url;
|
|
48
|
+
this.method = (init?.method ?? input.method).toUpperCase();
|
|
49
|
+
this.headers = new NitroHeaders(init?.headers
|
|
50
|
+
? init.headers instanceof NitroHeaders
|
|
51
|
+
? init.headers
|
|
52
|
+
: init.headers
|
|
53
|
+
: input.headers);
|
|
54
|
+
this.redirect =
|
|
55
|
+
init?.redirect ?? input.redirect ?? 'follow';
|
|
56
|
+
this.signal = init?.signal ?? input.signal;
|
|
57
|
+
this.cache = init?.cache ?? input.cache ?? 'default';
|
|
58
|
+
this.credentials =
|
|
59
|
+
init?.credentials ?? input.credentials ?? 'same-origin';
|
|
60
|
+
this.mode = init?.mode ?? input.mode ?? 'cors';
|
|
61
|
+
this.referrer = init?.referrer ?? input.referrer ?? 'about:client';
|
|
62
|
+
this.referrerPolicy =
|
|
63
|
+
init?.referrerPolicy ?? input.referrerPolicy ?? '';
|
|
64
|
+
this.integrity = init?.integrity ?? input.integrity ?? '';
|
|
65
|
+
this.keepalive = init?.keepalive ?? input.keepalive ?? false;
|
|
66
|
+
this._body = init?.body ?? null;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.url = String(input);
|
|
70
|
+
this.method = (init?.method ?? 'GET').toUpperCase();
|
|
71
|
+
this.headers = new NitroHeaders(init?.headers
|
|
72
|
+
? init.headers instanceof NitroHeaders
|
|
73
|
+
? init.headers
|
|
74
|
+
: init.headers
|
|
75
|
+
: undefined);
|
|
76
|
+
this.redirect = init?.redirect ?? 'follow';
|
|
77
|
+
this.signal = init?.signal ?? new AbortController().signal;
|
|
78
|
+
this.cache = init?.cache ?? 'default';
|
|
79
|
+
this.credentials = init?.credentials ?? 'same-origin';
|
|
80
|
+
this.mode = init?.mode ?? 'cors';
|
|
81
|
+
this.referrer = init?.referrer ?? 'about:client';
|
|
82
|
+
this.referrerPolicy = init?.referrerPolicy ?? '';
|
|
83
|
+
this.integrity = init?.integrity ?? '';
|
|
84
|
+
this.keepalive = init?.keepalive ?? false;
|
|
85
|
+
this._body = init?.body ?? null;
|
|
86
|
+
}
|
|
87
|
+
this.destination = '';
|
|
90
88
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
get bodyUsed() {
|
|
94
|
-
return this._bodyUsed;
|
|
95
|
-
}
|
|
96
|
-
get body() {
|
|
97
|
-
if (this._body == null) return null;
|
|
98
|
-
const bodyBytes = this._getBodyBytes();
|
|
99
|
-
if (!bodyBytes) return null;
|
|
100
|
-
return new ReadableStream({
|
|
101
|
-
start(controller) {
|
|
102
|
-
controller.enqueue(new Uint8Array(bodyBytes));
|
|
103
|
-
controller.close();
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
_throwIfBodyUsed() {
|
|
108
|
-
if (this._bodyUsed) {
|
|
109
|
-
throw new TypeError('Body has already been consumed.');
|
|
89
|
+
get bodyUsed() {
|
|
90
|
+
return this._bodyUsed;
|
|
110
91
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
92
|
+
get body() {
|
|
93
|
+
if (this._body == null)
|
|
94
|
+
return null;
|
|
95
|
+
const bodyBytes = this._getBodyBytes();
|
|
96
|
+
if (!bodyBytes)
|
|
97
|
+
return null;
|
|
98
|
+
return new ReadableStream({
|
|
99
|
+
start(controller) {
|
|
100
|
+
controller.enqueue(new Uint8Array(bodyBytes));
|
|
101
|
+
controller.close();
|
|
102
|
+
},
|
|
103
|
+
});
|
|
120
104
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
view.byteOffset,
|
|
126
|
-
view.byteOffset + view.byteLength
|
|
127
|
-
);
|
|
105
|
+
_throwIfBodyUsed() {
|
|
106
|
+
if (this._bodyUsed) {
|
|
107
|
+
throw new TypeError('Body has already been consumed.');
|
|
108
|
+
}
|
|
128
109
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
110
|
+
_getBodyBytes() {
|
|
111
|
+
if (this._body == null)
|
|
112
|
+
return undefined;
|
|
113
|
+
if (typeof this._body === 'string') {
|
|
114
|
+
const encoded = stringToUTF8(this._body);
|
|
115
|
+
return encoded.buffer.slice(encoded.byteOffset, encoded.byteOffset + encoded.byteLength);
|
|
116
|
+
}
|
|
117
|
+
if (this._body instanceof ArrayBuffer)
|
|
118
|
+
return this._body;
|
|
119
|
+
if (ArrayBuffer.isView(this._body)) {
|
|
120
|
+
const view = this._body;
|
|
121
|
+
return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
_getBodyString() {
|
|
126
|
+
if (this._body == null)
|
|
127
|
+
return '';
|
|
128
|
+
if (typeof this._body === 'string')
|
|
129
|
+
return this._body;
|
|
130
|
+
const bytes = this._getBodyBytes();
|
|
131
|
+
if (bytes)
|
|
132
|
+
return utf8ToString(new Uint8Array(bytes));
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
async text() {
|
|
136
|
+
this._throwIfBodyUsed();
|
|
137
|
+
this._bodyUsed = true;
|
|
138
|
+
return this._getBodyString();
|
|
139
|
+
}
|
|
140
|
+
async json() {
|
|
141
|
+
this._throwIfBodyUsed();
|
|
142
|
+
this._bodyUsed = true;
|
|
143
|
+
const t = this._getBodyString();
|
|
144
|
+
return JSON.parse(t || '{}');
|
|
145
|
+
}
|
|
146
|
+
async arrayBuffer() {
|
|
147
|
+
this._throwIfBodyUsed();
|
|
148
|
+
this._bodyUsed = true;
|
|
149
|
+
return this._getBodyBytes() ?? new ArrayBuffer(0);
|
|
150
|
+
}
|
|
151
|
+
async blob() {
|
|
152
|
+
this._throwIfBodyUsed();
|
|
153
|
+
this._bodyUsed = true;
|
|
154
|
+
const buffer = this._getBodyBytes() ?? new ArrayBuffer(0);
|
|
155
|
+
const contentType = this.headers.get('content-type') ?? '';
|
|
156
|
+
return new Blob([buffer], { type: contentType });
|
|
157
|
+
}
|
|
158
|
+
async bytes() {
|
|
159
|
+
this._throwIfBodyUsed();
|
|
160
|
+
this._bodyUsed = true;
|
|
161
|
+
const buffer = this._getBodyBytes() ?? new ArrayBuffer(0);
|
|
162
|
+
return new Uint8Array(buffer);
|
|
163
|
+
}
|
|
164
|
+
clone() {
|
|
165
|
+
if (this._bodyUsed) {
|
|
166
|
+
throw new TypeError('Cannot clone a Request whose body has been used.');
|
|
167
|
+
}
|
|
168
|
+
return new NitroRequest(this);
|
|
169
|
+
}
|
|
170
|
+
async formData() {
|
|
171
|
+
throw new TypeError('formData() is not supported in NitroRequest');
|
|
170
172
|
}
|
|
171
|
-
return new NitroRequest(this);
|
|
172
|
-
}
|
|
173
|
-
async formData() {
|
|
174
|
-
throw new TypeError('formData() is not supported in NitroRequest');
|
|
175
|
-
}
|
|
176
173
|
}
|