diff --git a/doc/api/http.md b/doc/api/http.md index 4c01ab3edb37c0..251f49645e2931 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -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 @@ -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)`][], @@ -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`. @@ -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 diff --git a/doc/api/https.md b/doc/api/https.md index f4c1f0487a779a..1a4a38252b6978 100644 --- a/doc/api/https.md +++ b/doc/api/https.md @@ -22,6 +22,8 @@ changes: sessions reuse. --> +XXX: UNDICI + An [`Agent`][] object for HTTPS similar to [`http.Agent`][]. See [`https.request()`][] for more information. @@ -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`. @@ -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: diff --git a/doc/api/zlib.md b/doc/api/zlib.md index 3187195a0e0a3a..beec48d67ad3c5 100644 --- a/doc/api/zlib.md +++ b/doc/api/zlib.md @@ -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