rezo 1.0.30 → 1.0.32
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/dist/adapters/curl.cjs +8 -10
- package/dist/adapters/curl.js +8 -10
- package/dist/adapters/entries/curl.d.ts +169 -313
- package/dist/adapters/entries/fetch.d.ts +169 -313
- package/dist/adapters/entries/http.d.ts +169 -313
- package/dist/adapters/entries/http2.d.ts +169 -313
- package/dist/adapters/entries/react-native.d.ts +169 -313
- package/dist/adapters/entries/xhr.d.ts +169 -313
- package/dist/adapters/fetch.cjs +10 -7
- package/dist/adapters/fetch.js +10 -7
- package/dist/adapters/http.cjs +9 -12
- package/dist/adapters/http.js +9 -12
- package/dist/adapters/http2.cjs +6 -11
- package/dist/adapters/http2.js +6 -11
- package/dist/adapters/index.cjs +6 -6
- package/dist/adapters/react-native.cjs +4 -4
- package/dist/adapters/react-native.js +4 -4
- package/dist/adapters/xhr.cjs +4 -4
- package/dist/adapters/xhr.js +4 -4
- package/dist/cache/index.cjs +13 -13
- package/dist/cache/universal-response-cache.cjs +165 -0
- package/dist/cache/universal-response-cache.js +162 -0
- package/dist/core/rezo.cjs +2 -8
- package/dist/core/rezo.js +2 -8
- package/dist/crawler.d.ts +163 -313
- package/dist/entries/crawler.cjs +5 -5
- package/dist/index.cjs +24 -24
- package/dist/index.d.ts +169 -313
- package/dist/platform/browser.d.ts +169 -313
- package/dist/platform/bun.d.ts +169 -313
- package/dist/platform/deno.d.ts +169 -313
- package/dist/platform/node.d.ts +169 -313
- package/dist/platform/react-native.d.ts +169 -313
- package/dist/platform/worker.d.ts +169 -313
- package/dist/plugin/crawler.cjs +1 -1
- package/dist/plugin/crawler.js +1 -1
- package/dist/plugin/index.cjs +36 -36
- package/dist/proxy/index.cjs +4 -4
- package/dist/queue/index.cjs +8 -8
- package/dist/responses/buildResponse.cjs +15 -15
- package/dist/responses/buildResponse.js +15 -15
- package/dist/responses/universal/download.cjs +23 -0
- package/dist/responses/universal/download.js +22 -0
- package/dist/responses/universal/event-emitter.cjs +104 -0
- package/dist/responses/universal/event-emitter.js +102 -0
- package/dist/responses/universal/index.cjs +11 -0
- package/dist/responses/universal/index.js +4 -0
- package/dist/responses/universal/stream.cjs +32 -0
- package/dist/responses/universal/stream.js +31 -0
- package/dist/responses/universal/upload.cjs +23 -0
- package/dist/responses/universal/upload.js +22 -0
- package/dist/utils/cookies.browser.cjs +63 -0
- package/dist/utils/cookies.browser.js +61 -0
- package/dist/utils/form-data.cjs +212 -189
- package/dist/utils/form-data.js +212 -189
- package/dist/utils/http-config.cjs +28 -15
- package/dist/utils/http-config.js +28 -15
- package/package.json +11 -4
- package/dist/types/cookies.cjs +0 -394
- package/dist/types/cookies.js +0 -391
package/dist/utils/form-data.js
CHANGED
|
@@ -1,218 +1,241 @@
|
|
|
1
|
-
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
const hasBuffer = typeof Buffer !== "undefined";
|
|
2
|
+
function isBuffer(value) {
|
|
3
|
+
return hasBuffer && Buffer.isBuffer(value);
|
|
4
|
+
}
|
|
5
|
+
function toBlob(value, contentType) {
|
|
6
|
+
const options = contentType ? { type: contentType } : undefined;
|
|
7
|
+
const copy = new ArrayBuffer(value.byteLength);
|
|
8
|
+
new Uint8Array(copy).set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
9
|
+
return new Blob([copy], options);
|
|
4
10
|
}
|
|
5
11
|
|
|
6
|
-
export class RezoFormData
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const entries = [];
|
|
13
|
-
const fields = this._fields || [];
|
|
14
|
-
for (const field of fields) {
|
|
15
|
-
if (field && field.name && field.value !== undefined) {
|
|
16
|
-
entries.push([field.name, field.value]);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
resolve(entries);
|
|
20
|
-
});
|
|
12
|
+
export class RezoFormData {
|
|
13
|
+
_fd;
|
|
14
|
+
_cachedContentType = null;
|
|
15
|
+
_cachedBuffer = null;
|
|
16
|
+
constructor() {
|
|
17
|
+
this._fd = new FormData;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
31
|
-
}
|
|
32
|
-
const buffer = Buffer.concat(chunks);
|
|
33
|
-
const blob = new Blob([buffer]);
|
|
34
|
-
formData.append(key, blob);
|
|
35
|
-
} else {
|
|
36
|
-
formData.append(key, value);
|
|
37
|
-
}
|
|
19
|
+
append(name, value, filename) {
|
|
20
|
+
this._invalidateCache();
|
|
21
|
+
if (isBuffer(value)) {
|
|
22
|
+
const blob = toBlob(value);
|
|
23
|
+
if (filename) {
|
|
24
|
+
this._fd.append(name, blob, filename);
|
|
25
|
+
} else {
|
|
26
|
+
this._fd.append(name, blob);
|
|
38
27
|
}
|
|
39
|
-
|
|
28
|
+
} else if (filename && value instanceof Blob) {
|
|
29
|
+
this._fd.append(name, value, filename);
|
|
30
|
+
} else {
|
|
31
|
+
this._fd.append(name, value);
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
const arrayBuffer = await file.arrayBuffer();
|
|
49
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
50
|
-
rezoFormData.append(key, buffer, {
|
|
51
|
-
filename: file.name,
|
|
52
|
-
contentType: file.type || "application/octet-stream"
|
|
53
|
-
});
|
|
54
|
-
} else if (typeof Blob !== "undefined" && value instanceof Blob) {
|
|
55
|
-
const blob = value;
|
|
56
|
-
const arrayBuffer = await blob.arrayBuffer();
|
|
57
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
58
|
-
rezoFormData.append(key, buffer, {
|
|
59
|
-
contentType: blob.type || "application/octet-stream"
|
|
60
|
-
});
|
|
33
|
+
}
|
|
34
|
+
set(name, value, filename) {
|
|
35
|
+
this._invalidateCache();
|
|
36
|
+
if (isBuffer(value)) {
|
|
37
|
+
const blob = toBlob(value);
|
|
38
|
+
if (filename) {
|
|
39
|
+
this._fd.set(name, blob, filename);
|
|
61
40
|
} else {
|
|
62
|
-
|
|
41
|
+
this._fd.set(name, blob);
|
|
63
42
|
}
|
|
43
|
+
} else if (filename && value instanceof Blob) {
|
|
44
|
+
this._fd.set(name, value, filename);
|
|
45
|
+
} else {
|
|
46
|
+
this._fd.set(name, value);
|
|
64
47
|
}
|
|
65
|
-
return rezoFormData;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
|
-
return
|
|
49
|
+
get(name) {
|
|
50
|
+
return this._fd.get(name);
|
|
69
51
|
}
|
|
70
|
-
|
|
71
|
-
return
|
|
52
|
+
getAll(name) {
|
|
53
|
+
return this._fd.getAll(name);
|
|
72
54
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
76
|
-
RezoFormData.appendValue(formData, key, value);
|
|
77
|
-
}
|
|
78
|
-
return formData;
|
|
55
|
+
has(name) {
|
|
56
|
+
return this._fd.has(name);
|
|
79
57
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
RezoFormData.appendValue(formData, key, item);
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
58
|
+
delete(name) {
|
|
59
|
+
this._invalidateCache();
|
|
60
|
+
this._fd.delete(name);
|
|
61
|
+
}
|
|
62
|
+
entries() {
|
|
63
|
+
return this._fd.entries();
|
|
64
|
+
}
|
|
65
|
+
keys() {
|
|
66
|
+
return this._fd.keys();
|
|
67
|
+
}
|
|
68
|
+
values() {
|
|
69
|
+
return this._fd.values();
|
|
70
|
+
}
|
|
71
|
+
forEach(callback) {
|
|
72
|
+
this._fd.forEach(callback);
|
|
73
|
+
}
|
|
74
|
+
[Symbol.iterator]() {
|
|
75
|
+
return this._fd.entries();
|
|
76
|
+
}
|
|
77
|
+
toNativeFormData() {
|
|
78
|
+
return this._fd;
|
|
79
|
+
}
|
|
80
|
+
_invalidateCache() {
|
|
81
|
+
this._cachedContentType = null;
|
|
82
|
+
this._cachedBuffer = null;
|
|
83
|
+
}
|
|
84
|
+
async _buildResponse() {
|
|
85
|
+
if (this._cachedBuffer === null || this._cachedContentType === null) {
|
|
86
|
+
const response = new Response(this._fd);
|
|
87
|
+
this._cachedContentType = response.headers.get("content-type") || "multipart/form-data";
|
|
88
|
+
this._cachedBuffer = await response.arrayBuffer();
|
|
89
|
+
}
|
|
90
|
+
return new Response(this._cachedBuffer, {
|
|
91
|
+
headers: { "content-type": this._cachedContentType }
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getBoundary() {
|
|
95
|
+
if (!this._cachedContentType) {
|
|
96
|
+
return "";
|
|
122
97
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
98
|
+
const match = this._cachedContentType.match(/boundary=([^;]+)/);
|
|
99
|
+
return match ? match[1] : "";
|
|
100
|
+
}
|
|
101
|
+
getContentType() {
|
|
102
|
+
return this._cachedContentType || undefined;
|
|
103
|
+
}
|
|
104
|
+
async getContentTypeAsync() {
|
|
105
|
+
await this._buildResponse();
|
|
106
|
+
return this._cachedContentType;
|
|
107
|
+
}
|
|
108
|
+
getHeaders() {
|
|
109
|
+
if (this._cachedContentType) {
|
|
110
|
+
return { "content-type": this._cachedContentType };
|
|
131
111
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
async getHeadersAsync() {
|
|
115
|
+
const contentType = await this.getContentTypeAsync();
|
|
116
|
+
const length = await this.getLength();
|
|
117
|
+
return {
|
|
118
|
+
"content-type": contentType,
|
|
119
|
+
"content-length": String(length)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
getLengthSync() {
|
|
123
|
+
return this._cachedBuffer?.byteLength;
|
|
124
|
+
}
|
|
125
|
+
async getLength() {
|
|
126
|
+
await this._buildResponse();
|
|
127
|
+
return this._cachedBuffer.byteLength;
|
|
128
|
+
}
|
|
129
|
+
getBuffer() {
|
|
130
|
+
if (!hasBuffer || !this._cachedBuffer) {
|
|
131
|
+
return null;
|
|
140
132
|
}
|
|
141
|
-
|
|
133
|
+
return Buffer.from(this._cachedBuffer);
|
|
142
134
|
}
|
|
143
|
-
async
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
135
|
+
async toBuffer() {
|
|
136
|
+
await this._buildResponse();
|
|
137
|
+
return Buffer.from(this._cachedBuffer);
|
|
138
|
+
}
|
|
139
|
+
async toArrayBuffer() {
|
|
140
|
+
await this._buildResponse();
|
|
141
|
+
return this._cachedBuffer;
|
|
142
|
+
}
|
|
143
|
+
async toUint8Array() {
|
|
144
|
+
await this._buildResponse();
|
|
145
|
+
return new Uint8Array(this._cachedBuffer);
|
|
146
|
+
}
|
|
147
|
+
static fromObject(obj) {
|
|
148
|
+
const fd = new RezoFormData;
|
|
149
|
+
const appendValue = (key, value) => {
|
|
150
|
+
if (value === null || value === undefined) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (typeof value === "string") {
|
|
154
|
+
fd.append(key, value);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
158
|
+
fd.append(key, String(value));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (value instanceof Blob) {
|
|
162
|
+
const filename = value instanceof File ? value.name : undefined;
|
|
163
|
+
fd.append(key, value, filename);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (isBuffer(value)) {
|
|
167
|
+
fd.append(key, toBlob(value));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (value instanceof Uint8Array) {
|
|
171
|
+
fd.append(key, toBlob(value));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (value instanceof ArrayBuffer) {
|
|
175
|
+
fd.append(key, new Blob([value]));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (Array.isArray(value)) {
|
|
179
|
+
for (let i = 0;i < value.length; i++) {
|
|
180
|
+
appendValue(`${key}[${i}]`, value[i]);
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (typeof value === "object" && value !== null) {
|
|
185
|
+
if ("value" in value && (("filename" in value) || ("contentType" in value))) {
|
|
186
|
+
const v = value;
|
|
187
|
+
if (v.value instanceof Blob) {
|
|
188
|
+
fd.append(key, v.value, v.filename);
|
|
189
|
+
} else if (isBuffer(v.value)) {
|
|
190
|
+
const blob = toBlob(v.value, v.contentType);
|
|
191
|
+
fd.append(key, blob, v.filename);
|
|
192
|
+
} else if (v.value instanceof Uint8Array) {
|
|
193
|
+
const blob = toBlob(v.value, v.contentType);
|
|
194
|
+
fd.append(key, blob, v.filename);
|
|
166
195
|
} else {
|
|
167
|
-
|
|
196
|
+
fd.append(key, String(v.value));
|
|
168
197
|
}
|
|
169
|
-
|
|
170
|
-
hasOmittedData = true;
|
|
198
|
+
return;
|
|
171
199
|
}
|
|
200
|
+
for (const [subKey, subValue] of Object.entries(value)) {
|
|
201
|
+
appendValue(`${key}[${subKey}]`, subValue);
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
172
204
|
}
|
|
173
|
-
|
|
174
|
-
|
|
205
|
+
fd.append(key, String(value));
|
|
206
|
+
};
|
|
207
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
208
|
+
appendValue(key, value);
|
|
175
209
|
}
|
|
176
|
-
|
|
177
|
-
|
|
210
|
+
return fd;
|
|
211
|
+
}
|
|
212
|
+
static fromNativeFormData(formData) {
|
|
213
|
+
const fd = new RezoFormData;
|
|
214
|
+
for (const [key, value] of formData.entries()) {
|
|
215
|
+
if (typeof value === "string") {
|
|
216
|
+
fd.append(key, value);
|
|
217
|
+
} else {
|
|
218
|
+
const filename = value.name || undefined;
|
|
219
|
+
fd.append(key, value, filename);
|
|
220
|
+
}
|
|
178
221
|
}
|
|
179
|
-
return
|
|
222
|
+
return fd;
|
|
180
223
|
}
|
|
181
|
-
|
|
224
|
+
toUrlQueryString() {
|
|
182
225
|
const params = new URLSearchParams;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
for (const [name, value] of entries) {
|
|
187
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
188
|
-
params.append(name, String(value));
|
|
189
|
-
} else if (value instanceof Buffer) {
|
|
190
|
-
if (convertBinaryToBase64) {
|
|
191
|
-
params.append(name, value.toString("base64"));
|
|
192
|
-
} else {
|
|
193
|
-
hasOmittedData = true;
|
|
194
|
-
}
|
|
195
|
-
} else if (isReadableStream(value) || typeof File !== "undefined" && value instanceof File || typeof Blob !== "undefined" && value instanceof Blob) {
|
|
196
|
-
if (convertBinaryToBase64 && value instanceof File) {
|
|
197
|
-
hasOmittedData = true;
|
|
198
|
-
} else {
|
|
199
|
-
hasOmittedData = true;
|
|
200
|
-
}
|
|
201
|
-
} else if (typeof value === "object" && value && "value" in value) {
|
|
202
|
-
if (typeof value.value === "string" || typeof value.value === "number" || typeof value.value === "boolean") {
|
|
203
|
-
params.append(name, String(value.value));
|
|
204
|
-
} else {
|
|
205
|
-
hasOmittedData = true;
|
|
206
|
-
}
|
|
207
|
-
} else {
|
|
208
|
-
hasOmittedData = true;
|
|
209
|
-
}
|
|
226
|
+
for (const [key, value] of this._fd.entries()) {
|
|
227
|
+
if (typeof value === "string") {
|
|
228
|
+
params.append(key, value);
|
|
210
229
|
}
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.warn("RezoFormData.toURLSearchParams(): Error reading form data entries:", error);
|
|
213
230
|
}
|
|
214
|
-
|
|
215
|
-
|
|
231
|
+
return params.toString();
|
|
232
|
+
}
|
|
233
|
+
toURLSearchParams() {
|
|
234
|
+
const params = new URLSearchParams;
|
|
235
|
+
for (const [key, value] of this._fd.entries()) {
|
|
236
|
+
if (typeof value === "string") {
|
|
237
|
+
params.append(key, value);
|
|
238
|
+
}
|
|
216
239
|
}
|
|
217
240
|
return params;
|
|
218
241
|
}
|
|
@@ -4,6 +4,10 @@ const { RezoHeaders } = require('./headers.cjs');
|
|
|
4
4
|
const { RezoURLSearchParams } = require('./data-operations.cjs');
|
|
5
5
|
const { parseProxyString } = require('../proxy/parse.cjs');
|
|
6
6
|
const { createDefaultHooks, mergeHooks, serializeHooks } = require('../core/hooks.cjs');
|
|
7
|
+
const hasBuffer = typeof Buffer !== "undefined";
|
|
8
|
+
function isBuffer(value) {
|
|
9
|
+
return hasBuffer && Buffer.isBuffer(value);
|
|
10
|
+
}
|
|
7
11
|
const ERROR_INFO = exports.ERROR_INFO = {
|
|
8
12
|
ECONNREFUSED: {
|
|
9
13
|
code: -111,
|
|
@@ -313,7 +317,6 @@ function prepareHTTPOptions(options, jar, addedOptions, config) {
|
|
|
313
317
|
if (options.formData || options.multipart) {
|
|
314
318
|
if (options.multipart instanceof RezoFormData || options.formData instanceof RezoFormData) {
|
|
315
319
|
const body = options.multipart instanceof RezoFormData ? options.multipart : options.formData;
|
|
316
|
-
contentType = body.getContentType();
|
|
317
320
|
fetchOptions.body = body;
|
|
318
321
|
} else {
|
|
319
322
|
const body = new RezoFormData;
|
|
@@ -322,27 +325,31 @@ function prepareHTTPOptions(options, jar, addedOptions, config) {
|
|
|
322
325
|
Object.entries(_body).forEach(([key, value]) => {
|
|
323
326
|
if (value === null || value === undefined) {
|
|
324
327
|
body.append(key, "");
|
|
325
|
-
} else if (typeof value === "string"
|
|
328
|
+
} else if (typeof value === "string") {
|
|
329
|
+
body.append(key, value);
|
|
330
|
+
} else if (isBuffer(value)) {
|
|
326
331
|
body.append(key, value);
|
|
327
|
-
} else if (
|
|
332
|
+
} else if (value instanceof Blob) {
|
|
328
333
|
body.append(key, value);
|
|
329
334
|
} else if (typeof value === "object" && value.value !== undefined) {
|
|
330
335
|
const val = value.value;
|
|
331
|
-
const
|
|
332
|
-
if (typeof val === "string"
|
|
333
|
-
body.append(key, val
|
|
336
|
+
const filename = value.options?.filename || value.filename;
|
|
337
|
+
if (typeof val === "string") {
|
|
338
|
+
body.append(key, val);
|
|
339
|
+
} else if (isBuffer(val)) {
|
|
340
|
+
body.append(key, val, filename);
|
|
341
|
+
} else if (val instanceof Blob) {
|
|
342
|
+
body.append(key, val, filename);
|
|
334
343
|
} else {
|
|
335
|
-
body.append(key, String(val)
|
|
344
|
+
body.append(key, String(val));
|
|
336
345
|
}
|
|
337
346
|
} else {
|
|
338
347
|
body.append(key, String(value));
|
|
339
348
|
}
|
|
340
349
|
});
|
|
341
350
|
}
|
|
342
|
-
contentType = body.getContentType();
|
|
343
351
|
fetchOptions.body = body;
|
|
344
352
|
}
|
|
345
|
-
fetchOptions.headers.set("Content-Type", contentType);
|
|
346
353
|
} else if (options.form) {
|
|
347
354
|
contentType = "application/x-www-form-urlencoded";
|
|
348
355
|
if (typeof options.form === "object") {
|
|
@@ -374,17 +381,23 @@ function prepareHTTPOptions(options, jar, addedOptions, config) {
|
|
|
374
381
|
Object.entries(fetchOptions.body).forEach(([key, value]) => {
|
|
375
382
|
if (value === null || value === undefined) {
|
|
376
383
|
formData.append(key, "");
|
|
377
|
-
} else if (typeof value === "string"
|
|
384
|
+
} else if (typeof value === "string") {
|
|
385
|
+
formData.append(key, value);
|
|
386
|
+
} else if (isBuffer(value)) {
|
|
378
387
|
formData.append(key, value);
|
|
379
|
-
} else if (
|
|
388
|
+
} else if (value instanceof Blob) {
|
|
380
389
|
formData.append(key, value);
|
|
381
390
|
} else if (typeof value === "object" && value.value !== undefined) {
|
|
382
391
|
const val = value.value;
|
|
383
|
-
const
|
|
384
|
-
if (typeof val === "string"
|
|
385
|
-
formData.append(key, val
|
|
392
|
+
const filename = value.options?.filename || value.filename;
|
|
393
|
+
if (typeof val === "string") {
|
|
394
|
+
formData.append(key, val);
|
|
395
|
+
} else if (isBuffer(val)) {
|
|
396
|
+
formData.append(key, val, filename);
|
|
397
|
+
} else if (val instanceof Blob) {
|
|
398
|
+
formData.append(key, val, filename);
|
|
386
399
|
} else {
|
|
387
|
-
formData.append(key, String(val)
|
|
400
|
+
formData.append(key, String(val));
|
|
388
401
|
}
|
|
389
402
|
} else {
|
|
390
403
|
formData.append(key, String(value));
|
|
@@ -4,6 +4,10 @@ import { RezoHeaders } from './headers.js';
|
|
|
4
4
|
import { RezoURLSearchParams } from './data-operations.js';
|
|
5
5
|
import { parseProxyString } from '../proxy/parse.js';
|
|
6
6
|
import { createDefaultHooks, mergeHooks, serializeHooks } from '../core/hooks.js';
|
|
7
|
+
const hasBuffer = typeof Buffer !== "undefined";
|
|
8
|
+
function isBuffer(value) {
|
|
9
|
+
return hasBuffer && Buffer.isBuffer(value);
|
|
10
|
+
}
|
|
7
11
|
export const ERROR_INFO = {
|
|
8
12
|
ECONNREFUSED: {
|
|
9
13
|
code: -111,
|
|
@@ -313,7 +317,6 @@ export function prepareHTTPOptions(options, jar, addedOptions, config) {
|
|
|
313
317
|
if (options.formData || options.multipart) {
|
|
314
318
|
if (options.multipart instanceof RezoFormData || options.formData instanceof RezoFormData) {
|
|
315
319
|
const body = options.multipart instanceof RezoFormData ? options.multipart : options.formData;
|
|
316
|
-
contentType = body.getContentType();
|
|
317
320
|
fetchOptions.body = body;
|
|
318
321
|
} else {
|
|
319
322
|
const body = new RezoFormData;
|
|
@@ -322,27 +325,31 @@ export function prepareHTTPOptions(options, jar, addedOptions, config) {
|
|
|
322
325
|
Object.entries(_body).forEach(([key, value]) => {
|
|
323
326
|
if (value === null || value === undefined) {
|
|
324
327
|
body.append(key, "");
|
|
325
|
-
} else if (typeof value === "string"
|
|
328
|
+
} else if (typeof value === "string") {
|
|
329
|
+
body.append(key, value);
|
|
330
|
+
} else if (isBuffer(value)) {
|
|
326
331
|
body.append(key, value);
|
|
327
|
-
} else if (
|
|
332
|
+
} else if (value instanceof Blob) {
|
|
328
333
|
body.append(key, value);
|
|
329
334
|
} else if (typeof value === "object" && value.value !== undefined) {
|
|
330
335
|
const val = value.value;
|
|
331
|
-
const
|
|
332
|
-
if (typeof val === "string"
|
|
333
|
-
body.append(key, val
|
|
336
|
+
const filename = value.options?.filename || value.filename;
|
|
337
|
+
if (typeof val === "string") {
|
|
338
|
+
body.append(key, val);
|
|
339
|
+
} else if (isBuffer(val)) {
|
|
340
|
+
body.append(key, val, filename);
|
|
341
|
+
} else if (val instanceof Blob) {
|
|
342
|
+
body.append(key, val, filename);
|
|
334
343
|
} else {
|
|
335
|
-
body.append(key, String(val)
|
|
344
|
+
body.append(key, String(val));
|
|
336
345
|
}
|
|
337
346
|
} else {
|
|
338
347
|
body.append(key, String(value));
|
|
339
348
|
}
|
|
340
349
|
});
|
|
341
350
|
}
|
|
342
|
-
contentType = body.getContentType();
|
|
343
351
|
fetchOptions.body = body;
|
|
344
352
|
}
|
|
345
|
-
fetchOptions.headers.set("Content-Type", contentType);
|
|
346
353
|
} else if (options.form) {
|
|
347
354
|
contentType = "application/x-www-form-urlencoded";
|
|
348
355
|
if (typeof options.form === "object") {
|
|
@@ -374,17 +381,23 @@ export function prepareHTTPOptions(options, jar, addedOptions, config) {
|
|
|
374
381
|
Object.entries(fetchOptions.body).forEach(([key, value]) => {
|
|
375
382
|
if (value === null || value === undefined) {
|
|
376
383
|
formData.append(key, "");
|
|
377
|
-
} else if (typeof value === "string"
|
|
384
|
+
} else if (typeof value === "string") {
|
|
385
|
+
formData.append(key, value);
|
|
386
|
+
} else if (isBuffer(value)) {
|
|
378
387
|
formData.append(key, value);
|
|
379
|
-
} else if (
|
|
388
|
+
} else if (value instanceof Blob) {
|
|
380
389
|
formData.append(key, value);
|
|
381
390
|
} else if (typeof value === "object" && value.value !== undefined) {
|
|
382
391
|
const val = value.value;
|
|
383
|
-
const
|
|
384
|
-
if (typeof val === "string"
|
|
385
|
-
formData.append(key, val
|
|
392
|
+
const filename = value.options?.filename || value.filename;
|
|
393
|
+
if (typeof val === "string") {
|
|
394
|
+
formData.append(key, val);
|
|
395
|
+
} else if (isBuffer(val)) {
|
|
396
|
+
formData.append(key, val, filename);
|
|
397
|
+
} else if (val instanceof Blob) {
|
|
398
|
+
formData.append(key, val, filename);
|
|
386
399
|
} else {
|
|
387
|
-
formData.append(key, String(val)
|
|
400
|
+
formData.append(key, String(val));
|
|
388
401
|
}
|
|
389
402
|
} else {
|
|
390
403
|
formData.append(key, String(value));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rezo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "Lightning-fast, enterprise-grade HTTP client for modern JavaScript. Full HTTP/2 support, intelligent cookie management, multiple adapters (HTTP, Fetch, cURL, XHR), streaming, proxy support (HTTP/HTTPS/SOCKS), and cross-environment compatibility.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"node": ">=22.0.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"form-data": "^4.0.4",
|
|
65
64
|
"tough-cookie": "^5.1.2",
|
|
66
65
|
"http-proxy-agent": "^7.0.2",
|
|
67
66
|
"https-proxy-agent": "^7.0.6",
|
|
@@ -211,12 +210,20 @@
|
|
|
211
210
|
"./dist/platform/node.js": "./dist/platform/browser.js",
|
|
212
211
|
"./dist/platform/node.cjs": "./dist/platform/browser.cjs",
|
|
213
212
|
"./dist/adapters/http.js": "./dist/adapters/fetch.js",
|
|
214
|
-
"./dist/adapters/http.cjs": "./dist/adapters/fetch.cjs"
|
|
213
|
+
"./dist/adapters/http.cjs": "./dist/adapters/fetch.cjs",
|
|
214
|
+
"./dist/utils/cookies.js": "./dist/utils/cookies.browser.js",
|
|
215
|
+
"./dist/utils/cookies.cjs": "./dist/utils/cookies.browser.cjs",
|
|
216
|
+
"./dist/cache/response-cache.js": "./dist/cache/universal-response-cache.js",
|
|
217
|
+
"./dist/cache/response-cache.cjs": "./dist/cache/universal-response-cache.cjs"
|
|
215
218
|
},
|
|
216
219
|
"react-native": {
|
|
217
220
|
"./dist/platform/node.js": "./dist/platform/react-native.js",
|
|
218
221
|
"./dist/platform/node.cjs": "./dist/platform/react-native.cjs",
|
|
219
|
-
"./dist/adapters/http.js": "./dist/adapters/react-native.js"
|
|
222
|
+
"./dist/adapters/http.js": "./dist/adapters/react-native.js",
|
|
223
|
+
"./dist/utils/cookies.js": "./dist/utils/cookies.browser.js",
|
|
224
|
+
"./dist/utils/cookies.cjs": "./dist/utils/cookies.browser.cjs",
|
|
225
|
+
"./dist/cache/response-cache.js": "./dist/cache/universal-response-cache.js",
|
|
226
|
+
"./dist/cache/response-cache.cjs": "./dist/cache/universal-response-cache.cjs"
|
|
220
227
|
},
|
|
221
228
|
"files": [
|
|
222
229
|
"dist/**/*",
|