Repository: nodejs/node
Pull request: doc: add missing `zstd` to mjs example of zlib

For reference, cjs example already has `zstd` as compression encoding.

1. Client request example

(1) mjs
https://github.com/nodejs/node/blob/6f7f51b8f104dcebb96ac407b489719cc51e124a/doc/api/zlib.md#L237-L273

(2) cjs

https://github.com/nodejs/node/blob/6f7f51b8f104dcebb96ac407b489719cc51e124a/doc/api/zlib.md#L277-L314

2. Server example

(1) mjs

https://github.com/nodejs/node/blob/6f7f51b8f104dcebb96ac407b489719cc51e124a/doc/api/zlib.md#L319-L360

(2) cjs

https://github.com/nodejs/node/blob/6f7f51b8f104dcebb96ac407b489719cc51e124a/doc/api/zlib.md#L364-L408

Refs: https://github.com/nodejs/node/pull/52100

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
4. Update documentation if relevant.
5. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: doc/api/zlib.md
patch: @@ -244,7 +244,7 @@ import { pipeline } from 'node:stream';
 const request = http.get({ host: 'example.com',
                            path: '/',
                            port: 80,
-                           headers: { 'Accept-Encoding': 'br,gzip,deflate' } });
+                           headers: { 'Accept-Encoding': 'br,gzip,deflate,zstd' } });
 request.on('response', (response) => {
   const output = fs.createWriteStream('example.com_index.html');
 
@@ -266,6 +266,9 @@ request.on('response', (response) => {
     case 'deflate':
       pipeline(response, zlib.createInflate(), output, onError);
       break;
+    case 'zstd':
+      pipeline(response, zlib.createZstdDecompress(), output, onError);
+      break;
     default:
       pipeline(response, output, onError);
       break;
@@ -353,6 +356,9 @@ http.createServer((request, response) => {
   } else if (/\bbr\b/.test(acceptEncoding)) {
     response.writeHead(200, { 'Content-Encoding': 'br' });
     pipeline(raw, zlib.createBrotliCompress(), response, onError);
+  } else if (/\bzstd\b/.test(acceptEncoding)) {
+    response.writeHead(200, { 'Content-Encoding': 'zstd' });
+    pipeline(raw, zlib.createZstdCompress(), response, onError);
   } else {
     response.writeHead(200, {});
     pipeline(raw, response, onError);