@indra211/exios 3.1.1 → 3.1.2
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/README.md +2 -0
- package/dist/index.cjs +11 -1
- package/dist/index.js +11 -1
- package/dist/index.node.cjs +36 -2
- package/dist/index.node.js +36 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ await exios.get(url, {
|
|
|
81
81
|
|
|
82
82
|
- **Proxy:** `proxy` wins; `proxy: false` disables proxying; otherwise `HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY` (and lowercase variants) are used, like axios. HTTPS targets go through a `CONNECT` tunnel, using the TLS options (`ca`, `rejectUnauthorized`, ...) of your `httpsAgent`. An `https:` proxy (`protocol: 'https'` or `HTTPS_PROXY=https://...`) is reached over TLS. Aborts and timeouts also tear down a `CONNECT` still in progress.
|
|
83
83
|
- **Redirects:** 303, and 301/302 after a POST, become GET without a body; 307/308 resend the method and body (a one-shot stream body cannot be resent, so the 307/308 is returned). A redirect to another host or port, or from `https:` to `http:`, drops `Authorization`, `Cookie` and `Proxy-Authorization`. A redirect that would have to resend a one-shot stream body is returned instead of followed. Too many redirects reject with `ERR_FR_TOO_MANY_REDIRECTS` (never retried).
|
|
84
|
+
- **Protocols:** only `http:` and `https:`. Any other URL (`file:`, `ftp:`, `data:`, ...), whether requested or reached through a redirect, rejects with `ERR_BAD_REQUEST` (`Unsupported protocol ftp:`) before anything is sent. A malformed `Location` header rejects with `ERR_BAD_RESPONSE`.
|
|
84
85
|
- **Network errors** keep `code: 'ERR_NETWORK'` (retry and the breaker depend on it); the Node error is in `error.cause`, so `error.cause.code` is `ECONNREFUSED`, `ECONNRESET`, `ENOTFOUND`, ... (axios puts that in `error.code` instead).
|
|
85
86
|
- **Bodies:** `FormData`, `Blob`, `URLSearchParams`, strings and typed arrays are buffered (so they are resent on retries and redirects, with an exact `Content-Length`); web `ReadableStream` and Node `Readable` bodies (including `fs` streams and the `form-data` package, whose `getHeaders()` boundary is used) are streamed and never retried. If a body stream fails, the request rejects with `ERR_BAD_REQUEST` (the stream's error is in `cause`), and an aborted or timed-out request destroys the body stream.
|
|
86
87
|
|
|
@@ -350,6 +351,7 @@ Also:
|
|
|
350
351
|
|
|
351
352
|
## Not supported
|
|
352
353
|
|
|
354
|
+
- `data:` URLs on the `http` adapter (axios decodes them; exios rejects them).
|
|
353
355
|
- `maxRate` (bandwidth limits), `lookup` / `family` DNS options, HTTP/2 on the `http` adapter.
|
|
354
356
|
- `redirect: 'manual' | 'error'` and `fetchOptions` on the `xhr` adapter (browsers' XHR always follows redirects); use `adapter: 'fetch'` when you need them.
|
|
355
357
|
- Distributed or persisted breaker state.
|
package/dist/index.cjs
CHANGED
|
@@ -282,7 +282,17 @@ function buildFullPath(baseURL, url, allowAbsoluteUrls = true) {
|
|
|
282
282
|
if (!baseURL) return u;
|
|
283
283
|
if (allowAbsoluteUrls && ABSOLUTE_URL.test(u)) return u;
|
|
284
284
|
if (!u) return baseURL;
|
|
285
|
-
return `${baseURL
|
|
285
|
+
return `${trimSlashes(baseURL, "end")}/${trimSlashes(u, "start")}`;
|
|
286
|
+
}
|
|
287
|
+
function trimSlashes(s, side) {
|
|
288
|
+
if (side === "start") {
|
|
289
|
+
let i = 0;
|
|
290
|
+
while (s.charCodeAt(i) === 47) i++;
|
|
291
|
+
return s.slice(i);
|
|
292
|
+
}
|
|
293
|
+
let j = s.length;
|
|
294
|
+
while (j > 0 && s.charCodeAt(j - 1) === 47) j--;
|
|
295
|
+
return s.slice(0, j);
|
|
286
296
|
}
|
|
287
297
|
|
|
288
298
|
// src/core/toFormData.ts
|
package/dist/index.js
CHANGED
|
@@ -256,7 +256,17 @@ function buildFullPath(baseURL, url, allowAbsoluteUrls = true) {
|
|
|
256
256
|
if (!baseURL) return u;
|
|
257
257
|
if (allowAbsoluteUrls && ABSOLUTE_URL.test(u)) return u;
|
|
258
258
|
if (!u) return baseURL;
|
|
259
|
-
return `${baseURL
|
|
259
|
+
return `${trimSlashes(baseURL, "end")}/${trimSlashes(u, "start")}`;
|
|
260
|
+
}
|
|
261
|
+
function trimSlashes(s, side) {
|
|
262
|
+
if (side === "start") {
|
|
263
|
+
let i = 0;
|
|
264
|
+
while (s.charCodeAt(i) === 47) i++;
|
|
265
|
+
return s.slice(i);
|
|
266
|
+
}
|
|
267
|
+
let j = s.length;
|
|
268
|
+
while (j > 0 && s.charCodeAt(j - 1) === 47) j--;
|
|
269
|
+
return s.slice(0, j);
|
|
260
270
|
}
|
|
261
271
|
|
|
262
272
|
// src/core/toFormData.ts
|
package/dist/index.node.cjs
CHANGED
|
@@ -216,7 +216,17 @@ function buildFullPath(baseURL, url, allowAbsoluteUrls = true) {
|
|
|
216
216
|
if (!baseURL) return u;
|
|
217
217
|
if (allowAbsoluteUrls && ABSOLUTE_URL.test(u)) return u;
|
|
218
218
|
if (!u) return baseURL;
|
|
219
|
-
return `${baseURL
|
|
219
|
+
return `${trimSlashes(baseURL, "end")}/${trimSlashes(u, "start")}`;
|
|
220
|
+
}
|
|
221
|
+
function trimSlashes(s, side) {
|
|
222
|
+
if (side === "start") {
|
|
223
|
+
let i = 0;
|
|
224
|
+
while (s.charCodeAt(i) === 47) i++;
|
|
225
|
+
return s.slice(i);
|
|
226
|
+
}
|
|
227
|
+
let j = s.length;
|
|
228
|
+
while (j > 0 && s.charCodeAt(j - 1) === 47) j--;
|
|
229
|
+
return s.slice(0, j);
|
|
220
230
|
}
|
|
221
231
|
|
|
222
232
|
// src/core/toFormData.ts
|
|
@@ -748,6 +758,7 @@ function canReplay(next) {
|
|
|
748
758
|
}
|
|
749
759
|
|
|
750
760
|
// src/adapters/http/index.ts
|
|
761
|
+
var SUPPORTED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
751
762
|
var CHUNK = 64 * 1024;
|
|
752
763
|
var DEFAULT_ACCEPT_ENCODING = "gzip, compress, deflate, br";
|
|
753
764
|
function requestOptions(hop, config) {
|
|
@@ -835,6 +846,8 @@ async function httpAdapter(config) {
|
|
|
835
846
|
e.cause = err;
|
|
836
847
|
throw e;
|
|
837
848
|
}
|
|
849
|
+
if (!SUPPORTED_PROTOCOLS.has(url.protocol))
|
|
850
|
+
throw new ExiosError(`Unsupported protocol ${url.protocol}`, ExiosError.ERR_BAD_REQUEST, config);
|
|
838
851
|
const hop = { url, method: prepared.method, headers, body };
|
|
839
852
|
return new Promise((resolve, reject) => {
|
|
840
853
|
const signal = config.signal;
|
|
@@ -929,7 +942,28 @@ async function httpAdapter(config) {
|
|
|
929
942
|
async function onResponse(incoming) {
|
|
930
943
|
const resHeaders = headersOf(incoming);
|
|
931
944
|
const status = incoming.statusCode ?? 0;
|
|
932
|
-
|
|
945
|
+
let next = null;
|
|
946
|
+
if (maxRedirects > 0) {
|
|
947
|
+
try {
|
|
948
|
+
next = nextRedirect(current, status, incoming.headers.location);
|
|
949
|
+
} catch (err) {
|
|
950
|
+
incoming.resume();
|
|
951
|
+
const e = new ExiosError(
|
|
952
|
+
`Invalid redirect location: ${incoming.headers.location}`,
|
|
953
|
+
ExiosError.ERR_BAD_RESPONSE,
|
|
954
|
+
config,
|
|
955
|
+
req
|
|
956
|
+
);
|
|
957
|
+
e.cause = err;
|
|
958
|
+
return fail(e);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
if (next && !SUPPORTED_PROTOCOLS.has(next.url.protocol)) {
|
|
962
|
+
incoming.resume();
|
|
963
|
+
return fail(
|
|
964
|
+
new ExiosError(`Unsupported protocol ${next.url.protocol}`, ExiosError.ERR_BAD_REQUEST, config, req)
|
|
965
|
+
);
|
|
966
|
+
}
|
|
933
967
|
if (next && canReplay(next)) {
|
|
934
968
|
if (++redirects > maxRedirects) {
|
|
935
969
|
incoming.resume();
|
package/dist/index.node.js
CHANGED
|
@@ -180,7 +180,17 @@ function buildFullPath(baseURL, url, allowAbsoluteUrls = true) {
|
|
|
180
180
|
if (!baseURL) return u;
|
|
181
181
|
if (allowAbsoluteUrls && ABSOLUTE_URL.test(u)) return u;
|
|
182
182
|
if (!u) return baseURL;
|
|
183
|
-
return `${baseURL
|
|
183
|
+
return `${trimSlashes(baseURL, "end")}/${trimSlashes(u, "start")}`;
|
|
184
|
+
}
|
|
185
|
+
function trimSlashes(s, side) {
|
|
186
|
+
if (side === "start") {
|
|
187
|
+
let i = 0;
|
|
188
|
+
while (s.charCodeAt(i) === 47) i++;
|
|
189
|
+
return s.slice(i);
|
|
190
|
+
}
|
|
191
|
+
let j = s.length;
|
|
192
|
+
while (j > 0 && s.charCodeAt(j - 1) === 47) j--;
|
|
193
|
+
return s.slice(0, j);
|
|
184
194
|
}
|
|
185
195
|
|
|
186
196
|
// src/core/toFormData.ts
|
|
@@ -712,6 +722,7 @@ function canReplay(next) {
|
|
|
712
722
|
}
|
|
713
723
|
|
|
714
724
|
// src/adapters/http/index.ts
|
|
725
|
+
var SUPPORTED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
715
726
|
var CHUNK = 64 * 1024;
|
|
716
727
|
var DEFAULT_ACCEPT_ENCODING = "gzip, compress, deflate, br";
|
|
717
728
|
function requestOptions(hop, config) {
|
|
@@ -799,6 +810,8 @@ async function httpAdapter(config) {
|
|
|
799
810
|
e.cause = err;
|
|
800
811
|
throw e;
|
|
801
812
|
}
|
|
813
|
+
if (!SUPPORTED_PROTOCOLS.has(url.protocol))
|
|
814
|
+
throw new ExiosError(`Unsupported protocol ${url.protocol}`, ExiosError.ERR_BAD_REQUEST, config);
|
|
802
815
|
const hop = { url, method: prepared.method, headers, body };
|
|
803
816
|
return new Promise((resolve, reject) => {
|
|
804
817
|
const signal = config.signal;
|
|
@@ -893,7 +906,28 @@ async function httpAdapter(config) {
|
|
|
893
906
|
async function onResponse(incoming) {
|
|
894
907
|
const resHeaders = headersOf(incoming);
|
|
895
908
|
const status = incoming.statusCode ?? 0;
|
|
896
|
-
|
|
909
|
+
let next = null;
|
|
910
|
+
if (maxRedirects > 0) {
|
|
911
|
+
try {
|
|
912
|
+
next = nextRedirect(current, status, incoming.headers.location);
|
|
913
|
+
} catch (err) {
|
|
914
|
+
incoming.resume();
|
|
915
|
+
const e = new ExiosError(
|
|
916
|
+
`Invalid redirect location: ${incoming.headers.location}`,
|
|
917
|
+
ExiosError.ERR_BAD_RESPONSE,
|
|
918
|
+
config,
|
|
919
|
+
req
|
|
920
|
+
);
|
|
921
|
+
e.cause = err;
|
|
922
|
+
return fail(e);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
if (next && !SUPPORTED_PROTOCOLS.has(next.url.protocol)) {
|
|
926
|
+
incoming.resume();
|
|
927
|
+
return fail(
|
|
928
|
+
new ExiosError(`Unsupported protocol ${next.url.protocol}`, ExiosError.ERR_BAD_REQUEST, config, req)
|
|
929
|
+
);
|
|
930
|
+
}
|
|
897
931
|
if (next && canReplay(next)) {
|
|
898
932
|
if (++redirects > maxRedirects) {
|
|
899
933
|
incoming.resume();
|
package/package.json
CHANGED