Skip to content

Commit

Permalink
Merge branch 'main' into http2
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Sep 8, 2023
2 parents b0a9667 + ea4f257 commit 1433624
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/bench.yml
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false
ref: ${{ github.base_ref }}
- name: Setup Node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: lts/*
- name: Install Modules
Expand All @@ -30,11 +30,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false
- name: Setup Node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: lts/*
- name: Install Modules
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Expand Up @@ -46,11 +46,11 @@ jobs:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.3.3
uses: github/codeql-action/init@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.3.3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -60,7 +60,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.3.3
uses: github/codeql-action/autobuild@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.3.3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -73,6 +73,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.3.3
uses: github/codeql-action/analyze@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.3.3
with:
category: "/language:${{matrix.language}}"
4 changes: 2 additions & 2 deletions .github/workflows/dependency-review.yml
Expand Up @@ -22,6 +22,6 @@ jobs:
egress-policy: audit

- name: 'Checkout Repository'
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: 'Dependency Review'
uses: actions/dependency-review-action@1360a344ccb0ab6e9475edef90ad2f46bf8003b1 # v3.0.6
uses: actions/dependency-review-action@f6fff72a3217f580d5afd49a46826795305b63c7 # v3.0.8
4 changes: 2 additions & 2 deletions .github/workflows/fuzz.yml
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: lts/*

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Expand Up @@ -7,10 +7,10 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
- uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: lts/*
- run: npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -34,6 +34,6 @@ jobs:
pull-requests: write
contents: write
steps:
- uses: fastify/github-action-merge-dependabot@d37100b180dfd816bb1d7e4fbb544b3c734957a1 # v3.9.0
- uses: fastify/github-action-merge-dependabot@59fc8817458fac20df8884576cfe69dbb77c9a07 # v3.9.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Expand Up @@ -29,7 +29,7 @@ jobs:

steps:
- name: "Checkout code"
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false

Expand All @@ -51,6 +51,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2
uses: github/codeql-action/upload-sarif@00e563ead9f72a8461b24876bee2d0c2e8bd2ee8 # v2.21.5
with:
sarif_file: results.sarif
40 changes: 22 additions & 18 deletions README.md
Expand Up @@ -18,30 +18,34 @@ npm i undici
## Benchmarks

The benchmark is a simple `hello world` [example](benchmarks/benchmark.js) using a
number of unix sockets (connections) with a pipelining depth of 10 running on Node 16.
The benchmarks below have the [simd](https://github.com/WebAssembly/simd) feature enabled.
number of unix sockets (connections) with a pipelining depth of 10 running on Node 20.6.0.

### Connections 1

| Tests | Samples | Result | Tolerance | Difference with slowest |
|---------------------|---------|---------------|-----------|-------------------------|
| http - no keepalive | 15 | 4.63 req/sec | ± 2.77 % | - |
| http - keepalive | 10 | 4.81 req/sec | ± 2.16 % | + 3.94 % |
| undici - stream | 25 | 62.22 req/sec | ± 2.67 % | + 1244.58 % |
| undici - dispatch | 15 | 64.33 req/sec | ± 2.47 % | + 1290.24 % |
| undici - request | 15 | 66.08 req/sec | ± 2.48 % | + 1327.88 % |
| undici - pipeline | 10 | 66.13 req/sec | ± 1.39 % | + 1329.08 % |

│ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │
|─────────────────────|─────────|───────────────|───────────|─────────────────────────|
│ http - no keepalive │ 15 │ 5.32 req/sec │ ± 2.61 % │ - │
│ http - keepalive │ 10 │ 5.35 req/sec │ ± 2.47 % │ + 0.44 % │
│ undici - fetch │ 15 │ 41.85 req/sec │ ± 2.49 % │ + 686.04 % │
│ undici - pipeline │ 40 │ 50.36 req/sec │ ± 2.77 % │ + 845.92 % │
│ undici - stream │ 15 │ 60.58 req/sec │ ± 2.75 % │ + 1037.72 % │
│ undici - request │ 10 │ 61.19 req/sec │ ± 2.60 % │ + 1049.24 % │
│ undici - dispatch │ 20 │ 64.84 req/sec │ ± 2.81 % │ + 1117.81 % │


### Connections 50

| Tests | Samples | Result | Tolerance | Difference with slowest |
|---------------------|---------|------------------|-----------|-------------------------|
| http - no keepalive | 50 | 3546.49 req/sec | ± 2.90 % | - |
| http - keepalive | 15 | 5692.67 req/sec | ± 2.48 % | + 60.52 % |
| undici - pipeline | 25 | 8478.71 req/sec | ± 2.62 % | + 139.07 % |
| undici - request | 20 | 9766.66 req/sec | ± 2.79 % | + 175.39 % |
| undici - stream | 15 | 10109.74 req/sec | ± 2.94 % | + 185.06 % |
| undici - dispatch | 25 | 10949.73 req/sec | ± 2.54 % | + 208.75 % |
│ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │
|─────────────────────|─────────|──────────────────|───────────|─────────────────────────|
│ undici - fetch │ 30 │ 2107.19 req/sec │ ± 2.69 % │ - │
│ http - no keepalive │ 10 │ 2698.90 req/sec │ ± 2.68 % │ + 28.08 % │
│ http - keepalive │ 10 │ 4639.49 req/sec │ ± 2.55 % │ + 120.17 % │
│ undici - pipeline │ 40 │ 6123.33 req/sec │ ± 2.97 % │ + 190.59 % │
│ undici - stream │ 50 │ 9426.51 req/sec │ ± 2.92 % │ + 347.35 % │
│ undici - request │ 10 │ 10162.88 req/sec │ ± 2.13 % │ + 382.29 % │
│ undici - dispatch │ 50 │ 11191.11 req/sec │ ± 2.98 % │ + 431.09 % │


## Quick Start

Expand Down
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -106,7 +106,10 @@ if (util.nodeMajor > 16 || (util.nodeMajor === 16 && util.nodeMinor >= 8)) {
try {
return await fetchImpl(...arguments)
} catch (err) {
Error.captureStackTrace(err, this)
if (typeof err === 'object') {
Error.captureStackTrace(err, this)
}

throw err
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/core/util.js
Expand Up @@ -359,15 +359,20 @@ function getSocketInfo (socket) {
}
}

async function * convertIterableToBuffer (iterable) {
for await (const chunk of iterable) {
yield Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
}
}

let ReadableStream
function ReadableStreamFrom (iterable) {
if (!ReadableStream) {
ReadableStream = require('stream/web').ReadableStream
}

if (ReadableStream.from) {
// https://github.com/whatwg/streams/pull/1083
return ReadableStream.from(iterable)
return ReadableStream.from(convertIterableToBuffer(iterable))
}

let iterator
Expand Down
1 change: 1 addition & 0 deletions lib/fetch/body.js
Expand Up @@ -387,6 +387,7 @@ function bodyMixinMethods (instance) {
try {
busboy = Busboy({
headers,
preservePath: true,
defParamCharset: 'utf8'
})
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -98,7 +98,7 @@
"standard": "^17.0.0",
"table": "^6.8.0",
"tap": "^16.1.0",
"tsd": "^0.28.1",
"tsd": "^0.29.0",
"typescript": "^5.0.2",
"wait-on": "^7.0.1",
"ws": "^8.11.0"
Expand Down
12 changes: 12 additions & 0 deletions test/fetch/client-fetch.js
Expand Up @@ -272,6 +272,18 @@ test('busboy emit error', async (t) => {
await t.rejects(res.formData(), 'Unexpected end of multipart data')
})

// https://github.com/nodejs/undici/issues/2244
test('parsing formData preserve full path on files', async (t) => {
t.plan(1)
const formData = new FormData()
formData.append('field1', new File(['foo'], 'a/b/c/foo.txt'))

const tempRes = new Response(formData)
const form = await tempRes.formData()

t.equal(form.get('field1').name, 'a/b/c/foo.txt')
})

test('urlencoded formData', (t) => {
t.plan(2)

Expand Down
8 changes: 8 additions & 0 deletions test/fetch/issue-2242.js
@@ -0,0 +1,8 @@
'use strict'

const { test } = require('tap')
const { fetch } = require('../..')

test('fetch with signal already aborted', async (t) => {
await t.rejects(fetch('http://localhost', { signal: AbortSignal.abort('Already aborted') }), 'Already aborted')
})
13 changes: 12 additions & 1 deletion test/utils/redirecting-servers.js
Expand Up @@ -2,6 +2,17 @@

const { createServer } = require('http')

function close (server) {
return function () {
return new Promise(resolve => {
if (typeof server.closeAllConnections === 'function') {
server.closeAllConnections()
}
server.close(resolve)
})
}
}

function startServer (t, handler) {
return new Promise(resolve => {
const server = createServer(handler)
Expand All @@ -10,7 +21,7 @@ function startServer (t, handler) {
resolve(`localhost:${server.address().port}`)
})

t.teardown(server.close.bind(server))
t.teardown(close(server))
})
}

Expand Down

0 comments on commit 1433624

Please sign in to comment.