mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
chore: migrate get stream to latest (#7516)
* build: bump get-stream to v9 * test: migrate helper buffer reads to get-stream v9 API * fix: tests with sessions * chore: update stream handler to better manage sessions * chore: revert some changes * chore: swap to buffer * chore: add port for stream test * chore: swap localhost * chore: change timeout * chore: update to stream type * chore: try again * chore: tests * chore: updat tests/unit/adapters/http.test.js to check ipv4 Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
Generated
+32
-5
@@ -38,7 +38,7 @@
|
|||||||
"formdata-node": "^5.0.1",
|
"formdata-node": "^5.0.1",
|
||||||
"formidable": "^2.1.5",
|
"formidable": "^2.1.5",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"get-stream": "^3.0.0",
|
"get-stream": "^9.0.1",
|
||||||
"globals": "^17.4.0",
|
"globals": "^17.4.0",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
@@ -3521,6 +3521,13 @@
|
|||||||
"win32"
|
"win32"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"node_modules/@sec-ant/readable-stream": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@sigstore/bundle": {
|
"node_modules/@sigstore/bundle": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sigstore/bundle/-/bundle-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sigstore/bundle/-/bundle-3.1.0.tgz",
|
||||||
@@ -7299,13 +7306,33 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/get-stream": {
|
"node_modules/get-stream": {
|
||||||
"version": "3.0.0",
|
"version": "9.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-9.0.1.tgz",
|
||||||
"integrity": "sha512-GlhdIUuVakc8SJ6kK0zAFbiGzRFzNnY4jUuEbV9UROo4Y+0Ny4fjvcZFVTeDA4odpFyOQzaw6hXukJSq/f28sQ==",
|
"integrity": "sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@sec-ant/readable-stream": "^0.4.1",
|
||||||
|
"is-stream": "^4.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/get-stream/node_modules/is-stream": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=4"
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/get-value": {
|
"node_modules/get-value": {
|
||||||
|
|||||||
+2
-2
@@ -111,7 +111,7 @@
|
|||||||
"formdata-node": "^5.0.1",
|
"formdata-node": "^5.0.1",
|
||||||
"formidable": "^2.1.5",
|
"formidable": "^2.1.5",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"get-stream": "^3.0.0",
|
"get-stream": "^9.0.1",
|
||||||
"globals": "^17.4.0",
|
"globals": "^17.4.0",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
@@ -184,4 +184,4 @@
|
|||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{js,cjs,mjs,ts,json,md,yml,yaml}": "prettier --write"
|
"*.{js,cjs,mjs,ts,json,md,yml,yaml}": "prettier --write"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import http from 'http';
|
import http from 'http';
|
||||||
import http2 from 'http2';
|
import http2 from 'http2';
|
||||||
import stream from 'stream';
|
import stream from 'stream';
|
||||||
import getStream from 'get-stream';
|
import getStream, { getStreamAsBuffer } from 'get-stream';
|
||||||
import { Throttle } from 'stream-throttle';
|
import { Throttle } from 'stream-throttle';
|
||||||
import formidable from 'formidable';
|
import formidable from 'formidable';
|
||||||
import selfsigned from 'selfsigned';
|
import selfsigned from 'selfsigned';
|
||||||
@@ -196,7 +196,7 @@ export const startTestServer = async (port) => {
|
|||||||
response.form = fields;
|
response.form = fields;
|
||||||
response.files = files;
|
response.files = files;
|
||||||
} else {
|
} else {
|
||||||
response.body = (await getStream(req, { encoding: 'buffer' })).toString('hex');
|
response.body = (await getStreamAsBuffer(req)).toString('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -2158,10 +2158,12 @@ describe('supports http with nodejs', function () {
|
|||||||
app.post('/', function (req, res) {
|
app.post('/', function (req, res) {
|
||||||
var parserRanBeforeHandler = Boolean(req.body && Object.keys(req.body).length);
|
var parserRanBeforeHandler = Boolean(req.body && Object.keys(req.body).length);
|
||||||
|
|
||||||
res.send(JSON.stringify({
|
res.send(
|
||||||
parserRanBeforeHandler: parserRanBeforeHandler,
|
JSON.stringify({
|
||||||
body: req.body,
|
parserRanBeforeHandler: parserRanBeforeHandler,
|
||||||
}));
|
body: req.body,
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
server = app.listen(3001, function () {
|
server = app.listen(3001, function () {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import http from 'http';
|
import http from 'http';
|
||||||
import http2 from 'http2';
|
import http2 from 'http2';
|
||||||
import stream from 'stream';
|
import stream from 'stream';
|
||||||
import getStream from 'get-stream';
|
import getStream, { getStreamAsBuffer } from 'get-stream';
|
||||||
import { Throttle } from 'stream-throttle';
|
import { Throttle } from 'stream-throttle';
|
||||||
import formidable from 'formidable';
|
import formidable from 'formidable';
|
||||||
import selfsigned from 'selfsigned';
|
import selfsigned from 'selfsigned';
|
||||||
@@ -211,7 +211,7 @@ export const startTestServer = async (port) => {
|
|||||||
response.form = fields;
|
response.form = fields;
|
||||||
response.files = files;
|
response.files = files;
|
||||||
} else {
|
} else {
|
||||||
response.body = (await getStream(req, { encoding: 'buffer' })).toString('hex');
|
response.body = (await getStreamAsBuffer(req)).toString('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3180,7 +3180,7 @@ describe('supports http with nodejs', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should merge request http2Options with its instance config', async () => {
|
it('should merge request http2Options with its instance config', async () => {
|
||||||
const http2Axios = createHttp2Axios('https://127.0.0.1:8080');
|
const http2Axios = createHttp2Axios('https://localhost:8080');
|
||||||
|
|
||||||
const { data } = await http2Axios.get('/', {
|
const { data } = await http2Axios.get('/', {
|
||||||
http2Options: {
|
http2Options: {
|
||||||
@@ -3211,7 +3211,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
const { data } = await http2Axios.get(localServerURL);
|
const { data } = await http2Axios.get(localServerURL);
|
||||||
assert.deepStrictEqual(data, 'OK');
|
assert.deepStrictEqual(data, 'OK');
|
||||||
@@ -3227,7 +3227,7 @@ describe('supports http with nodejs', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
const payload = 'DATA';
|
const payload = 'DATA';
|
||||||
const { data } = await http2Axios.post(localServerURL, payload);
|
const { data } = await http2Axios.post(localServerURL, payload);
|
||||||
@@ -3260,7 +3260,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('x', 'foo');
|
form.append('x', 'foo');
|
||||||
@@ -3302,7 +3302,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
const { data } = await http2Axios.get(localServerURL, {
|
const { data } = await http2Axios.get(localServerURL, {
|
||||||
responseType,
|
responseType,
|
||||||
@@ -3333,7 +3333,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
server.on('stream', (http2Stream) => {
|
server.on('stream', (http2Stream) => {
|
||||||
@@ -3378,7 +3378,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
server.on('stream', (http2Stream) => {
|
server.on('stream', (http2Stream) => {
|
||||||
@@ -3419,7 +3419,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
server.on('stream', (http2Stream) => {
|
server.on('stream', (http2Stream) => {
|
||||||
@@ -3470,7 +3470,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
const [response1, response2] = await Promise.all([
|
const [response1, response2] = await Promise.all([
|
||||||
@@ -3519,8 +3519,8 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const localServerURL2 = `https://127.0.0.1:${server2.address().port}`;
|
const localServerURL2 = `https://localhost:${server2.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
const [response1, response2] = await Promise.all([
|
const [response1, response2] = await Promise.all([
|
||||||
@@ -3557,28 +3557,24 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
const [response1, response2] = await Promise.all([
|
const [response1, response2] = await Promise.all([
|
||||||
http2Axios.get(localServerURL, {
|
http2Axios.get(localServerURL, {
|
||||||
responseType: 'stream',
|
http2Options: {
|
||||||
http2Options: {},
|
sessionTimeout: 2000,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
http2Axios.get(localServerURL, {
|
http2Axios.get(localServerURL, {
|
||||||
responseType: 'stream',
|
|
||||||
http2Options: {
|
http2Options: {
|
||||||
foo: 'test',
|
sessionTimeout: 4000,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert.notStrictEqual(response1.data.session, response2.data.session);
|
assert.notStrictEqual(response1.request.session, response2.request.session);
|
||||||
|
assert.deepStrictEqual([response1.data, response2.data], ['OK', 'OK']);
|
||||||
assert.deepStrictEqual(
|
|
||||||
await Promise.all([getStream(response1.data), getStream(response2.data)]),
|
|
||||||
['OK', 'OK']
|
|
||||||
);
|
|
||||||
} finally {
|
} finally {
|
||||||
await stopHTTPServer(server);
|
await stopHTTPServer(server);
|
||||||
}
|
}
|
||||||
@@ -3596,7 +3592,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
const responses = await Promise.all([
|
const responses = await Promise.all([
|
||||||
@@ -3638,7 +3634,7 @@ describe('supports http with nodejs', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localServerURL = `https://127.0.0.1:${server.address().port}`;
|
const localServerURL = `https://localhost:${server.address().port}`;
|
||||||
const http2Axios = createHttp2Axios(localServerURL);
|
const http2Axios = createHttp2Axios(localServerURL);
|
||||||
|
|
||||||
const response1 = await http2Axios.get(localServerURL, {
|
const response1 = await http2Axios.get(localServerURL, {
|
||||||
@@ -3648,6 +3644,7 @@ describe('supports http with nodejs', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const session1 = response1.data.session;
|
||||||
const data1 = await getStream(response1.data);
|
const data1 = await getStream(response1.data);
|
||||||
|
|
||||||
await setTimeoutAsync(5000);
|
await setTimeoutAsync(5000);
|
||||||
@@ -3659,9 +3656,10 @@ describe('supports http with nodejs', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const session2 = response2.data.session;
|
||||||
const data2 = await getStream(response2.data);
|
const data2 = await getStream(response2.data);
|
||||||
|
|
||||||
assert.notStrictEqual(response1.data.session, response2.data.session);
|
assert.notStrictEqual(session1, session2);
|
||||||
assert.strictEqual(data1, 'OK');
|
assert.strictEqual(data1, 'OK');
|
||||||
assert.strictEqual(data2, 'OK');
|
assert.strictEqual(data2, 'OK');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -3672,10 +3670,13 @@ describe('supports http with nodejs', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not abort stream on settle rejection', async () => {
|
it('should not abort stream on settle rejection', async () => {
|
||||||
const server = await startHTTPServer((req, res) => {
|
const server = await startHTTPServer(
|
||||||
res.statusCode = 404;
|
(req, res) => {
|
||||||
res.end('OK');
|
res.statusCode = 404;
|
||||||
});
|
res.end('OK');
|
||||||
|
},
|
||||||
|
{ port: SERVER_PORT }
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let error;
|
let error;
|
||||||
|
|||||||
Reference in New Issue
Block a user