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

doc: add undici notes #39057

Closed
wants to merge 5 commits into from
Closed
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
8 changes: 8 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ list like the following:
added: v0.3.4
-->

XXX: UNDICI

An `Agent` is responsible for managing connection persistence
and reuse for HTTP clients. It maintains a queue of pending requests
for a given host and port, reusing a single socket connection for each
Expand Down Expand Up @@ -373,6 +375,8 @@ agent. Do not modify.
added: v0.1.17
-->

XXX: UNDICI

* Extends: {Stream}

This object is created internally and returned from [`http.request()`][]. It
Expand Down Expand Up @@ -2705,6 +2709,8 @@ changes:
description: The `options` parameter can be a WHATWG `URL` object.
-->

XXX: UNDICI

* `url` {string | URL}
* `options` {Object} Accepts the same `options` as
[`http.request()`][], with the `method` always set to `GET`.
Expand Down Expand Up @@ -2824,6 +2830,8 @@ changes:
description: The `options` parameter can be a WHATWG `URL` object.
-->

XXX: UNDICI

* `url` {string | URL}
* `options` {Object}
* `agent` {http.Agent | boolean} Controls [`Agent`][] behavior. Possible
Expand Down
6 changes: 6 additions & 0 deletions doc/api/https.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ changes:
sessions reuse.
-->

XXX: UNDICI

An [`Agent`][] object for HTTPS similar to [`http.Agent`][]. See
[`https.request()`][] for more information.

Expand Down Expand Up @@ -212,6 +214,8 @@ changes:
description: The `options` parameter can be a WHATWG `URL` object.
-->

XXX: UNDICI

* `url` {string | URL}
* `options` {Object | string | URL} Accepts the same `options` as
[`https.request()`][], with the `method` always set to `GET`.
Expand Down Expand Up @@ -268,6 +272,8 @@ changes:
description: The `options` parameter can be a WHATWG `URL` object.
-->

XXX: UNDICI

* `url` {string | URL}
* `options` {Object | string | URL} Accepts all `options` from
[`http.request()`][], with some differences in default values:
Expand Down
57 changes: 24 additions & 33 deletions doc/api/zlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,41 +140,32 @@ tradeoffs involved in `zlib` usage.

```js
// Client request example
const zlib = require('zlib');
const http = require('http');
const fs = require('fs');
const { pipeline } = require('stream');
import zlib from 'zlib';
import undici from 'undici';
import fs from 'fs';
import { pipeline } from 'stream/promises';

const request = http.get({ host: 'example.com',
path: '/',
port: 80,
headers: { 'Accept-Encoding': 'br,gzip,deflate' } });
request.on('response', (response) => {
const output = fs.createWriteStream('example.com_index.html');

const onError = (err) => {
if (err) {
console.error('An error occurred:', err);
process.exitCode = 1;
}
};

switch (response.headers['content-encoding']) {
case 'br':
pipeline(response, zlib.createBrotliDecompress(), output, onError);
break;
// Or, just use zlib.createUnzip() to handle both of the following cases:
case 'gzip':
pipeline(response, zlib.createGunzip(), output, onError);
break;
case 'deflate':
pipeline(response, zlib.createInflate(), output, onError);
break;
default:
pipeline(response, output, onError);
break;
}
const { body, headers } = await undici.request('http://example.com:80', {
headers: { 'Accept-Encoding': 'br,gzip,deflate' }
});

const output = fs.createWriteStream('example.com_index.html');

switch (headers['content-encoding']) {
case 'br':
await pipeline(body, zlib.createBrotliDecompress(), output);
break;
// Or, just use zlib.createUnzip() to handle both of the following cases:
case 'gzip':
await pipeline(body, zlib.createGunzip(), output);
break;
case 'deflate':
await pipeline(body, zlib.createInflate(), output);
break;
default:
await pipeline(body, output);
break;
}
```

```js
Expand Down