Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '16, 18, 20, 22, 23'
version: '16, 18, 20, 22, 24'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ content-type: application/json
}
```

This exmaple can use `options.data` with `application/json` content type:
This example can use `options.data` with `application/json` content type:

```js
await request('https://example.com', {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"test": "npm run lint -- --fix && vitest run",
"test-keepalive": "cross-env TEST_KEEPALIVE_COUNT=50 vitest run --test-timeout 180000 keep-alive-header.test.ts",
"test-node16": "node examples/httpclient.cjs && node examples/search_github.cjs && node examples/timing.cjs",
"cov": "cross-env NODE_OPTIONS='--require ./test/patch-structuredClone.cjs' vitest run --coverage",
"cov": "cross-env NODE_OPTIONS=\"--require ./test/patch-for-node16-18.cjs\" vitest run --coverage",
"ci": "npm run lint && npm run cov && npm run prepublishOnly && npm pack && attw --pack",
"clean": "rm -rf dist",
"clean": "rm -rf dist && tsc -b --clean",
"prepublishOnly": "npm run build"
},
"dependencies": {
Expand Down Expand Up @@ -74,11 +74,12 @@
"iconv-lite": "^0.6.3",
"proxy": "^1.0.2",
"selfsigned": "^2.4.1",
"string.prototype.towellformed": "^1.0.2",
"tar-stream": "^2.2.0",
"tshy": "^3.0.0",
"tshy-after": "^1.0.0",
"typescript": "^5.0.4",
"vitest": "^3.0.2"
"vitest": "^3.2.4"
},
"engines": {
"node": ">= 18.19.0"
Expand Down
6 changes: 4 additions & 2 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ export class HttpClient extends EventEmitter {
return poolStatsMap;
}
for (const [ key, ref ] of clients) {
const pool = typeof ref.deref === 'function' ? ref.deref() : ref as unknown as Pool;
const stats = pool?.stats;
const pool = (typeof ref.deref === 'function' ? ref.deref() : ref) as unknown as (Pool & { dispatcher: Pool });
// NOTE: pool become to { dispatcher: Pool } in undici@v7
const stats = pool?.stats ?? pool?.dispatcher?.stats;
if (!stats) continue;

poolStatsMap[key] = {
connected: stats.connected,
free: stats.free,
Expand Down
6 changes: 4 additions & 2 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ export class FetchFactory {
return poolStatsMap;
}
for (const [ key, ref ] of clients) {
const pool = typeof ref.deref === 'function' ? ref.deref() : ref as unknown as Pool;
const stats = pool?.stats;
const pool = (typeof ref.deref === 'function' ? ref.deref() : ref) as unknown as (Pool & { dispatcher: Pool });
// NOTE: pool become to { dispatcher: Pool } in undici@v7
const stats = pool?.stats ?? pool?.dispatcher?.stats;
if (!stats) continue;

poolStatsMap[key] = {
connected: stats.connected,
free: stats.free,
Expand Down
3 changes: 2 additions & 1 deletion test/HttpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ describe('HttpClient.test.ts', () => {

const response = await httpclient.request(_url);
assert.equal(response.status, 200);
assert.equal(Object.keys(httpclient.getDispatcherPoolStats()).length, 1);
assert.equal(Object.keys(httpclient.getDispatcherPoolStats()).length, 1,
`dispatcher pool stats: ${JSON.stringify(httpclient.getDispatcherPoolStats())}`);
});

it('should check non-ip hostname with custom lookup', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('fetch.test.ts', () => {

const stats = FetchFactory.getDispatcherPoolStats();
assert(stats);
assert(Object.keys(stats).length > 0);
assert(Object.keys(stats).length > 0, `dispatcher pool stats: ${JSON.stringify(stats)}`);
});

it('fetch request with post should work', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/socket_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createServer, Server } from 'node:http';

const socketPathPrefix = '/tmp/urllib.unix.sock';
let index = 0;

export async function startServer(): Promise<{
server: Server,
url: string,
Expand Down
2 changes: 1 addition & 1 deletion test/options.socketPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe.skipIf(isWindows())('options.socketPath.test.ts', () => {

afterAll(async () => {
await close();
await server2.closeServer();
await server2?.closeServer();
});

it('should request socket successfully', async () => {
Expand Down
18 changes: 18 additions & 0 deletions test/patch-for-node16-18.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// vitest require structuredClone
if (!('structuredClone' in globalThis)) {
const structuredClone = require('@ungap/structured-clone').default;

globalThis.structuredClone = structuredClone;
// console.debug('patched structuredClone for Node.js %s', process.version);
}

// vitest require crypto.getRandomValues
const crypto = require('node:crypto');
if (typeof crypto.getRandomValues !== 'function') {
crypto.getRandomValues = crypto.webcrypto.getRandomValues.bind(crypto.webcrypto);
}

// undici@v7 require String.prototype.toWellFormed, patch on Node.js 16 and 18
if (typeof String.prototype.toWellFormed !== 'function') {
require('string.prototype.towellformed/auto');
}
7 changes: 0 additions & 7 deletions test/patch-structuredClone.cjs

This file was deleted.