Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add H2 support #33

Closed
wants to merge 123 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
d8d3c94
docs(Dispatcher): adjust documentation for reset flag (#1852)
metcoder95 Jan 11, 2023
e926fa4
Fix broken interceptor test (#1853)
mcollina Jan 11, 2023
8c90b01
Bumped v5.15.0
mcollina Jan 11, 2023
d5af7dd
fix(websocket): simplify typedarray copying (#1854)
KhafraDev Jan 12, 2023
f9aa0f1
fix: wpts on node v18.13.0+ (#1859)
KhafraDev Jan 17, 2023
61246a5
perf: allow keep alive for HEAD requests (#1858)
ronag Jan 17, 2023
16c4128
fix: flaky abort test (#1863)
KhafraDev Jan 18, 2023
c9d4a6b
fix: flaky abort test
ronag Jan 19, 2023
9d5f231
5.15.1
ronag Jan 19, 2023
2d2512c
fix: don't load websockets w/o crypto support (#1868)
KhafraDev Jan 19, 2023
22d2f70
fix: don't include websockets in node bundle (#1869)
merceyz Jan 19, 2023
f61a902
fix: don't set socket on client before init
ronag Jan 20, 2023
d6ba9e5
Fix fetch parameters not being applied correctly (#1870)
xconverge Jan 20, 2023
5883598
fix: typo in contributing.md (#1874)
debadree25 Jan 20, 2023
1813408
chore(performance#38): Performance improvements (#1871)
metcoder95 Jan 20, 2023
d7602f6
perf(util): improve isFormDataLike checks (#1875)
mateonunez Jan 21, 2023
9457c97
5.15.2
ronag Jan 22, 2023
69ede10
Add feature to specify custom headers for proxies (#1877)
Sebmaster Jan 22, 2023
d0a99c2
fix: don't swallow llhttp loading error
ronag Jan 23, 2023
81b1521
5.16.0
ronag Jan 23, 2023
bdb1d08
fix(wpts): Blob is a global getter in >=v19.x.x (#1880)
KhafraDev Jan 24, 2023
f02ab5b
doc: fix anchor links dispatcher.stream (#1881)
RafaelGSS Jan 25, 2023
25a8aac
wpt: make runner more resilient (#1884)
KhafraDev Jan 26, 2023
47f574d
Make test pass in v19.x (#1879)
mcollina Jan 26, 2023
196c4da
remove timeout-minutes in github action
mcollina Jan 27, 2023
a9dabd5
Correct the type of DispatchOptions["headers"] (#1896)
pan93412 Jan 29, 2023
67e9796
perf(content-type parser): faster string collector (#1894)
KhafraDev Jan 29, 2023
f4693d6
feat: expose content-type parser (#1895)
KhafraDev Jan 29, 2023
0c75102
Update DispatchOptions type (#1889)
xconverge Jan 29, 2023
055780a
fix: update error type definitions (#1888)
rafaelcr Jan 30, 2023
db0b5ca
fix: ensure connection header is a string (#1900)
ronag Feb 1, 2023
2b260c9
fix: throw if invalid content-type header (#1901)
ronag Feb 1, 2023
0986381
fix(fetch): use semicolon for Cookie header delimiter (#1906)
KhafraDev Feb 3, 2023
208f7cf
perf: use FastBuffer (#1907)
ronag Feb 4, 2023
16b7a68
5.17.0
ronag Feb 4, 2023
d2be675
fix: bad buffer slice
ronag Feb 4, 2023
ce6a53b
5.17.1
ronag Feb 4, 2023
b4c0e5a
Add ability to set TCP keepalive (#1904)
xconverge Feb 4, 2023
b06f19f
use faster timers (#1908)
ronag Feb 5, 2023
3bc7b4c
fix: ensure header value is a string (#1899)
ronag Feb 6, 2023
6641f93
fix: flaky test
ronag Feb 6, 2023
9dceb21
5.18.0
ronag Feb 6, 2023
7827031
fix(fetch): raise AbortSignal max event listeners (#1910)
KhafraDev Feb 7, 2023
c0ba75f
fix: content-disposition header parsing (#1911)
climba03003 Feb 8, 2023
0a59535
fix: remove test (#1916)
KhafraDev Feb 8, 2023
ba5ef44
feat: add Headers.prototype.getSetCookie (#1915)
KhafraDev Feb 8, 2023
87fa734
fix(headers): clone getSetCookie list & add getSetCookie type (#1917)
KhafraDev Feb 9, 2023
e155c6d
doc(mock): update out-of-date reply documentation (#1913)
p9f Feb 10, 2023
aebb232
fix(types): add missing keepAlive params (#1918)
SkeLLLa Feb 13, 2023
f7c6c6a
Make the fetch() abort test pass locally, on Linux and Mac, Node 18 a…
mcollina Feb 13, 2023
f5c89e5
Bumped v5.19.0
mcollina Feb 13, 2023
a2eff05
Merge pull request from GHSA-5r9g-qh6m-jxff
ronag Feb 13, 2023
f2324e5
Merge pull request from GHSA-r6ch-mqf9-qc9w
Trott Feb 13, 2023
6c32c0f
lint fixes
mcollina Feb 13, 2023
984d53b
Bumped v5.19.1
mcollina Feb 13, 2023
2971280
perf: improve cookie parsing performance (#1931)
KhafraDev Feb 15, 2023
f73ec63
fix: disable websocket wpts in ci :( (#1932)
KhafraDev Feb 15, 2023
c2387e8
fix: Allow “undefined“ as value in headers (#1929)
pan93412 Feb 15, 2023
eae6807
feat: Support autoSelectFamily when connecting. (#1914)
ShogunPanda Feb 15, 2023
8b8bfa7
fix: copy cookies when cloning haders (#1936)
KhafraDev Feb 16, 2023
eaf4dc9
test: more logs in wpt runner (#1933)
KhafraDev Feb 16, 2023
30dafe3
feat: change headersTimeout and bodyTimeout to 300s (#1937)
kyrylkov Feb 17, 2023
28b9dea
Bumped v5.20.0
mcollina Feb 18, 2023
d8d9a96
Create scorecard.yml (#1942)
RafaelGSS Feb 20, 2023
d04ec2b
ci: timeout CI jobs after 15 minutes (#1946)
dominykas Feb 21, 2023
5851019
test(wpt): respect variants (#1951)
panva Feb 21, 2023
ab494d2
fix: improve isFormDataLike compat (#1953)
ronag Feb 21, 2023
bc8e2b8
fix: flaky fetch tests (#1956)
KhafraDev Feb 22, 2023
474f54f
test(wpt): include all testing files (#1954)
KhafraDev Feb 22, 2023
0beedf9
fix: remove unneeded fetch tests (#1960)
KhafraDev Feb 22, 2023
e959307
fix: use normal timers for delays < 1s (#1961)
ronag Feb 22, 2023
b13312d
perf: optimize happy path (#1955)
anonrig Feb 22, 2023
178a97c
fix: 🐛 add URL upstream variations in BalancedPool types (#1966)
jimmy-guzman Feb 22, 2023
0faf03e
test(wpt): handle uncaught exceptions (#1965)
KhafraDev Feb 23, 2023
324f3e3
Fix failing wpts (#1967)
KhafraDev Feb 23, 2023
236df29
test(wpt): add results to an existing WPT Report (#1944)
panva Feb 23, 2023
e461407
fix: strengthen isStream condition checking (#1969)
debadree25 Feb 23, 2023
987d23d
fix: implement basic policy container (#1970)
KhafraDev Feb 24, 2023
06f77a9
TypeScript type fixes, for #1949 (#1968)
joshxyzhimself Feb 24, 2023
49c6b48
websocket: separate connection logic from websocket (#1973)
KhafraDev Feb 26, 2023
97ab273
README: h3 not showing ### as a header (#1975)
hilleer Feb 27, 2023
2f463fc
wptrunner: expose gc (#1974)
KhafraDev Feb 27, 2023
41aab94
perf: cork socket before writing (#1982)
ronag Mar 2, 2023
4885b11
fix: fast timers and event loop lag (#1977)
ronag Mar 3, 2023
71c3605
fix: correctly calculate resource timing duration (#1988)
amilajack Mar 4, 2023
3606c35
wpt: update tests (#1984)
KhafraDev Mar 4, 2023
a0afde8
fix: undici stream throwOnError (#1995)
dancastillo Mar 10, 2023
babed9c
fix: remove unnecessary WeakRef (#2000)
ronag Mar 10, 2023
0d2f4f1
Add missing import (#1997)
blazingzephyr Mar 10, 2023
65eea9b
feat: add abort signal to body.dump() (#1993)
debadree25 Mar 10, 2023
06c6488
fix(fetch): third party abortcontrollers throwing errors (#2002)
KhafraDev Mar 11, 2023
1bbcfa2
Improve ProxyAgent example with autentication (#2004)
egmen Mar 13, 2023
90d45fa
Add clientFactory option to ProxyAgent (#2003)
andrewfecenko Mar 13, 2023
98b63b2
Bumped v5.21.0
mcollina Mar 13, 2023
f04f9fa
Fix typo in kPipelining symbol (#2005)
andrewfecenko Mar 13, 2023
a64eb26
fix(fetch): remove `undefined` error cause (#2006)
aduh95 Mar 13, 2023
ebf0b45
chore(deps-dev): bump tsd from 0.25.0 to 0.27.0 (#2007)
dependabot[bot] Mar 13, 2023
6ec8f4e
build(deps-dev): bump wait-on from 6.0.1 to 7.0.1 (#1820)
dependabot[bot] Mar 13, 2023
4e1e0d0
fix(wpt): set global META_TITLE for the runner (#2008)
panva Mar 14, 2023
6fd7477
fix: issue 2009 (#2013)
KhafraDev Mar 17, 2023
7276126
build(deps-dev): bump typescript from 4.9.5 to 5.0.2 (#2018)
dependabot[bot] Mar 20, 2023
e6fc80f
added descriptive error messages for URL parser (#2016)
RishabhKodes Mar 22, 2023
f0271d4
fix(fetch): remove content-length header on redirect (#2022)
KhafraDev Mar 25, 2023
a9ef509
fix(fetch): remove assertion on request.body.source on redirect (#202…
macno Mar 28, 2023
dc8d111
fix: skip failing test in node >= v19.8 (#2034)
KhafraDev Mar 29, 2023
9013a23
fetch: treat content-encoding as case-insensitive & remove x-deflate …
KhafraDev Mar 31, 2023
7ae1779
perf(fetch): use string comparisons for url schemes (#2038)
KhafraDev Apr 1, 2023
549e7ed
util: replace util.toUSVString with String.prototype.toWellFormed (#2…
KhafraDev Apr 1, 2023
a6d1474
build(deps): bump github/codeql-action from 2.2.4 to 2.2.9 (#2039)
dependabot[bot] Apr 1, 2023
3d21d22
build(deps-dev): bump concurrently from 7.6.0 to 8.0.1 (#2041)
dependabot[bot] Apr 3, 2023
5f3b8e1
Small performance improvements (#2044)
anonrig Apr 4, 2023
eceaf9a
fix(types): Add missing Blob import (#2047)
dpogue Apr 4, 2023
816dcaa
fix: set window option properly (#2048)
KhafraDev Apr 5, 2023
a1846e5
fetch: fix leak (#2049)
ronag Apr 8, 2023
2d94417
5.21.1
ronag Apr 8, 2023
fb84aac
Content disposition parsing (#2051)
KhafraDev Apr 8, 2023
0562e9b
fix: clear set-cookie headers (#2052)
KhafraDev Apr 8, 2023
b20405e
5.21.2
ronag Apr 9, 2023
31884e6
build(deps-dev): bump tsd from 0.27.0 to 0.28.1 (#2042)
dependabot[bot] Apr 9, 2023
8c07892
build(deps): bump ossf/scorecard-action from 2.1.2 to 2.1.3 (#2040)
dependabot[bot] Apr 9, 2023
fa4ba00
fix: handle opaque origin in sameOrigin (#2053)
KhafraDev Apr 9, 2023
dfaec78
test: add typescript import test back (#2054)
KhafraDev Apr 9, 2023
b3eb287
feat: port H2 work with latest main
metcoder95 Apr 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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,7 @@ jobs:
with:
runs-on: ubuntu-latest, windows-latest
test-command: npm run coverage:ci
timeout-minutes: 15
post-test-steps: |
- name: Coverage Report
uses: codecov/codecov-action@v3
Expand All @@ -22,7 +23,6 @@ jobs:
exclude: |
- runs-on: windows-latest
node-version: 16
- node-version: 19
automerge:
if: >
github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.

name: Scorecard supply-chain security
on:
# For Branch-Protection check. Only the default branch is supported. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
branch_protection_rule:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '16 10 * * 2'
push:
branches: [ "main" ]

# Declare default permissions as read only.
permissions: read-all

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write

steps:
- name: "Checkout code"
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@80e868c13c90f172d68d1f4501dee99e2479f7af # v2.1.3
with:
results_file: results.sarif
results_format: sarif
publish_results: true

# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@04df1262e6247151b5ac09cd2c303ac36ad3f62b # v2.2.9
with:
sarif_file: results.sarif
62 changes: 61 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [Lint](#lint)
* [Test](#test)
* [Coverage](#coverage)
* [Update `WPTs`](#update-wpts)
* [Developer's Certificate of Origin 1.1](#developers-certificate-of-origin)
* [Moderation Policy](#moderation-policy)

Expand Down Expand Up @@ -50,7 +51,7 @@ npm i
> This requires [docker](https://www.docker.com/) installed on your machine.

```bash
npm run build-wasm
npm run build:wasm
```

#### Copy the sources to `undici`
Expand All @@ -77,6 +78,65 @@ cd <your-path-to-undici>
npm run build:wasm
```

<a id="update-wpts"></a>
### Update `WPTs`

`undici` runs a subset of the [`web-platform-tests`](https://github.com/web-platform-tests/wpt).

Here are the steps to update them.

<details>
<summary>Skip the tutorial</summary>

```bash
git clone --depth 1 --single-branch --branch epochs/daily --filter=blob:none --sparse https://github.com/web-platform-tests/wpt.git test/wpt/tests
cd test/wpt/tests
git sparse-checkout add /fetch
git sparse-checkout add /FileAPI
git sparse-checkout add /xhr
git sparse-checkout add /websockets
git sparse-checkout add /resources
git sparse-checkout add /common
git sparse-checkout add /mimesniff
git sparse-checkout add /interfaces
git sparse-checkout add /resources
```
</details>

#### Sparse-clone the [wpt](https://github.com/web-platform-tests/wpt) repo

```bash
git clone --depth 1 --single-branch --branch epochs/daily --filter=blob:none --sparse https://github.com/web-platform-tests/wpt.git test/wpt/tests

cd test/wpt/tests

```

#### Checkout the tests

Only run the commands for the folder(s) you want to update.

```bash
git sparse-checkout add /fetch
git sparse-checkout add /FileAPI
git sparse-checkout add /xhr
git sparse-checkout add /websockets
git sparse-checkout add /resources
git sparse-checkout add /common

# etc
```

#### Run the tests

Run the tests to ensure that any new failures are marked as such.

You can mark tests as failing in their corresponding [status](./test/wpt/status) file.

```bash
npm run test:wpt
```

<a id="lint"></a>

### Lint
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,18 @@ implementations in Deno and Cloudflare Workers.

Refs: https://fetch.spec.whatwg.org/#atomic-http-redirect-handling

## Workarounds

### Network address family autoselection.

If you experience problem when connecting to a remote server that is resolved by your DNS servers to a IPv6 (AAAA record)
first, there are chances that your local router or ISP might have problem connecting to IPv6 networks. In that case
undici will throw an error with code `UND_ERR_CONNECT_TIMEOUT`.

If the target server resolves to both a IPv6 and IPv4 (A records) address and you are using a compatible Node version
(18.3.0 and above), you can fix the problem by providing the `autoSelectFamily` option (support by both `undici.request`
and `undici.Agent`) which will enable the family autoselection algorithm when establishing the connection.

## Collaborators

* [__Daniele Belardi__](https://github.com/dnlup), <https://www.npmjs.com/~dnlup>
Expand Down
8 changes: 6 additions & 2 deletions docs/api/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Returns: `Client`

### Parameter: `ClientOptions`

* **bodyTimeout** `number | null` (optional) - Default: `30e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 30 seconds.
* **headersTimeout** `number | null` (optional) - Default: `30e3` - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 30 seconds.
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
* **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout` when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
* **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
* **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `1e3` - A number subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 1 second.
Expand All @@ -28,6 +28,8 @@ Returns: `Client`
* **connect** `ConnectOptions | Function | null` (optional) - Default: `null`.
* **strictContentLength** `Boolean` (optional) - Default: `true` - Whether to treat request content length mismatches as errors. If true, an error is thrown when the request content-length header doesn't match the length of the request body.
* **interceptors** `{ Client: DispatchInterceptor[] }` - Default: `[RedirectInterceptor]` - A list of interceptors that are applied to the dispatch method. Additional logic can be applied (such as, but not limited to: 302 status code handling, authentication, cookies, compression and caching). Note that the behavior of interceptors is Experimental and might change at any given time.
* **autoSelectFamily**: `boolean` (optional) - Default: depends on local Node version, on Node 18.13.0 and above is `false`. Enables a family autodetection algorithm that loosely implements section 5 of [RFC 8305](https://tools.ietf.org/html/rfc8305#section-5). See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details. This option is ignored if not supported by the current Node version.
* **autoSelectFamilyAttemptTimeout**: `number` - Default: depends on local Node version, on Node 18.13.0 and above is `250`. The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details.

#### Parameter: `ConnectOptions`

Expand All @@ -38,6 +40,8 @@ Furthermore, the following options can be passed:
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
* **timeout** `number | null` (optional) - Default `10e3`
* **servername** `string | null` (optional)
* **keepAlive** `boolean | null` (optional) - Default: `true` - TCP keep-alive enabled
* **keepAliveInitialDelay** `number | null` (optional) - Default: `60000` - TCP keep-alive interval for the socket in milliseconds

### Example - Basic Client instantiation

Expand Down
57 changes: 57 additions & 0 deletions docs/api/ContentType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# MIME Type Parsing

## `MIMEType` interface

* **type** `string`
* **subtype** `string`
* **parameters** `Map<string, string>`
* **essence** `string`

## `parseMIMEType(input)`

Implements [parse a MIME type](https://mimesniff.spec.whatwg.org/#parse-a-mime-type).

Parses a MIME type, returning its type, subtype, and any associated parameters. If the parser can't parse an input it returns the string literal `'failure'`.

```js
import { parseMIMEType } from 'undici'

parseMIMEType('text/html; charset=gbk')
// {
// type: 'text',
// subtype: 'html',
// parameters: Map(1) { 'charset' => 'gbk' },
// essence: 'text/html'
// }
```

Arguments:

* **input** `string`

Returns: `MIMEType|'failure'`

## `serializeAMimeType(input)`

Implements [serialize a MIME type](https://mimesniff.spec.whatwg.org/#serialize-a-mime-type).

Serializes a MIMEType object.

```js
import { serializeAMimeType } from 'undici'

serializeAMimeType({
type: 'text',
subtype: 'html',
parameters: new Map([['charset', 'gbk']]),
essence: 'text/html'
})
// text/html;charset=gbk

```

Arguments:

* **mimeType** `MIMEType`

Returns: `string`
20 changes: 10 additions & 10 deletions docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Returns: `void | Promise<ConnectData>` - Only returns a `Promise` if no `callbac
#### Parameter: `ConnectData`

* **statusCode** `number`
* **headers** `http.IncomingHttpHeaders`
* **headers** `Record<string, string | string[] | undefined>`
* **socket** `stream.Duplex`
* **opaque** `unknown`

Expand Down Expand Up @@ -192,15 +192,15 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
* **origin** `string | URL`
* **path** `string`
* **method** `string`
* **reset** `boolean` (optional) - Default: `false` - Indicates whether the request should attempt to create a long-living connection by sending the `connection: keep-alive` header, or close it immediately after response by sending `connection: close`.
* **reset** `boolean` (optional) - Default: `false` - If `false`, the request will attempt to create a long-living connection by sending the `connection: keep-alive` header,otherwise will attempt to close it immediately after response by sending `connection: close` within the request and closing the socket afterwards.
* **body** `string | Buffer | Uint8Array | stream.Readable | Iterable | AsyncIterable | null` (optional) - Default: `null`
* **headers** `UndiciHeaders | string[]` (optional) - Default: `null`.
* **query** `Record<string, any> | null` (optional) - Default: `null` - Query string params to be embedded in the request URL. Note that both keys and values of query are encoded using `encodeURIComponent`. If for some reason you need to send them unencoded, embed query params into path directly instead.
* **idempotent** `boolean` (optional) - Default: `true` if `method` is `'HEAD'` or `'GET'` - Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline has completed.
* **blocking** `boolean` (optional) - Default: `false` - Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received.
* **upgrade** `string | null` (optional) - Default: `null` - Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`.
* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 30 seconds.
* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 30 seconds.
* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
* **throwOnError** `boolean` (optional) - Default: `false` - Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server.

#### Parameter: `DispatchHandler`
Expand Down Expand Up @@ -383,7 +383,7 @@ Extends: [`RequestOptions`](#parameter-requestoptions)
#### Parameter: PipelineHandlerData

* **statusCode** `number`
* **headers** `IncomingHttpHeaders`
* **headers** `Record<string, string | string[] | undefined>`
* **opaque** `unknown`
* **body** `stream.Readable`
* **context** `object`
Expand Down Expand Up @@ -477,7 +477,7 @@ The `RequestOptions.method` property should not be value `'CONNECT'`.
#### Parameter: `ResponseData`

* **statusCode** `number`
* **headers** `http.IncomingHttpHeaders` - Note that all header keys are lower-cased, e. g. `content-type`.
* **headers** `Record<string, string | string[]>` - Note that all header keys are lower-cased, e. g. `content-type`.
* **body** `stream.Readable` which also implements [the body mixin from the Fetch Standard](https://fetch.spec.whatwg.org/#body-mixin).
* **trailers** `Record<string, string>` - This object starts out
as empty and will be mutated to contain trailers after `body` has emitted `'end'`.
Expand Down Expand Up @@ -631,7 +631,7 @@ try {

A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream.

As demonstrated in [Example 1 - Basic GET stream request](#example-1-basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2-stream-to-fastify-response) for more details.
As demonstrated in [Example 1 - Basic GET stream request](#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2---stream-to-fastify-response) for more details.

Arguments:

Expand All @@ -644,7 +644,7 @@ Returns: `void | Promise<StreamData>` - Only returns a `Promise` if no `callback
#### Parameter: `StreamFactoryData`

* **statusCode** `number`
* **headers** `http.IncomingHttpHeaders`
* **headers** `Record<string, string | string[] | undefined>`
* **opaque** `unknown`
* **onInfo** `({statusCode: number, headers: Record<string, string | string[]>}) => void | null` (optional) - Default: `null` - Callback collecting all the info headers (HTTP 100-199) received.

Expand Down Expand Up @@ -853,9 +853,9 @@ Emitted when dispatcher is no longer busy.

## Parameter: `UndiciHeaders`

* `http.IncomingHttpHeaders | string[] | null`
* `Record<string, string | string[] | undefined> | string[] | null`

Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in two forms; either as an object specified by the `http.IncomingHttpHeaders` type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown.
Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in two forms; either as an object specified by the `Record<string, string | string[] | undefined>` (`IncomingHttpHeaders`) type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown.

Keys are lowercase and values are not modified.

Expand Down
3 changes: 2 additions & 1 deletion docs/api/MockPool.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Returns: `MockInterceptor` corresponding to the input options.

We can define the behaviour of an intercepted request with the following options.

* **reply** `(statusCode: number, replyData: string | Buffer | object | MockInterceptor.MockResponseDataHandler, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. You can define this as a callback to read incoming request data. Default for `responseOptions` is `{}`.
* **reply** `(statusCode: number, replyData: string | Buffer | object | MockInterceptor.MockResponseDataHandler, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. You can define the replyData as a callback to read incoming request data. Default for `responseOptions` is `{}`.
* **reply** `(callback: MockInterceptor.MockReplyOptionsCallback) => MockScope` - define a reply for a matching request, allowing dynamic mocking of all reply options rather than just the data.
* **replyWithError** `(error: Error) => MockScope` - define an error for a matching request to throw.
* **defaultReplyHeaders** `(headers: Record<string, string>) => MockInterceptor` - define default headers to be included in subsequent replies. These are in addition to headers on a specific reply.
* **defaultReplyTrailers** `(trailers: Record<string, string>) => MockInterceptor` - define default trailers to be included in subsequent replies. These are in addition to trailers on a specific reply.
Expand Down
4 changes: 3 additions & 1 deletion docs/api/ProxyAgent.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Extends: [`AgentOptions`](Agent.md#parameter-agentoptions)
* **uri** `string` (required) - It can be passed either by a string or a object containing `uri` as string.
* **token** `string` (optional) - It can be passed by a string of token for authentication.
* **auth** `string` (**deprecated**) - Use token.
* **clientFactory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`

Examples:

Expand Down Expand Up @@ -83,7 +84,8 @@ import { setGlobalDispatcher, request, ProxyAgent } from 'undici';

const proxyAgent = new ProxyAgent({
uri: 'my.proxy.server',
token: 'Bearer xxxx'
// token: 'Bearer xxxx'
token: `Basic ${Buffer.from('username:password').toString('base64')}`
});
setGlobalDispatcher(proxyAgent);

Expand Down
Loading