Skip to content

Commit

Permalink
doc: add undici notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jun 17, 2021
1 parent 842554f commit 080dd60
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
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 @@ -375,6 +377,8 @@ added: v0.1.17

* Extends: {Stream}

XXX: UNDICI

This object is created internally and returned from [`http.request()`][]. It
represents an _in-progress_ request whose header has already been queued. The
header is still mutable using the [`setHeader(name, value)`][],
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
48 changes: 20 additions & 28 deletions doc/api/zlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,40 +141,32 @@ tradeoffs involved in `zlib` usage.
```js
// Client request example
const zlib = require('zlib');
const http = require('http');
const undici = require('undici');
const fs = require('fs');
const { pipeline } = require('stream');
const { pipeline } = require('stream/promises');

const request = http.get({ host: 'example.com',
const { body, headers } = await undici.request({ 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 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

0 comments on commit 080dd60

Please sign in to comment.