diff options
author | Fabian Meyer <3982806+meyfa@users.noreply.github.com> | 2022-10-17 17:57:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 17:57:28 +0300 |
commit | 76c9f046fba44d6dd37f6c5dcc5f1a025abca8f9 (patch) | |
tree | 14e2713ea9b3a995a904beb3cc16ab547393ac51 /doc | |
parent | 6adaf23c20acc48b836134ea660dc8c16f028117 (diff) |
doc: fix http and http2 writeEarlyHints() parameter
Both http and http2 `response.writeEarlyHints()` take an object,
not an array, as their first parameter. For http, this was updated in
the examples via #44820 except for the final example, which this
patch fixes.
The doc for the http2 version was not touched in #44820 although
I am pretty sure from skimming the code that it behaves identically
to http, and so propose to change its doc as well.
Finally, some bogus headline levels are fixed in http2 docs.
PR-URL: https://github.com/nodejs/node/pull/45000
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/http.md | 4 | ||||
-rw-r--r-- | doc/api/http2.md | 18 |
2 files changed, 14 insertions, 8 deletions
diff --git a/doc/api/http.md b/doc/api/http.md index 1b3a91e9deb..e942582b6b7 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -2175,7 +2175,9 @@ response.writeEarlyHints({ }); const earlyHintsCallback = () => console.log('early hints message sent'); -response.writeEarlyHints(earlyHintsLinks, earlyHintsCallback); +response.writeEarlyHints({ + 'link': earlyHintsLinks, +}, earlyHintsCallback); ``` ### `response.writeHead(statusCode[, statusMessage][, headers])` diff --git a/doc/api/http2.md b/doc/api/http2.md index c0031966840..6dbc6f93cc8 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -3787,7 +3787,7 @@ Removes a header that has been queued for implicit sending. response.removeHeader('Content-Encoding'); ``` -### `response.req` +#### `response.req` <!-- YAML added: v15.7.0 @@ -4005,30 +4005,34 @@ Sends a status `100 Continue` to the client, indicating that the request body should be sent. See the [`'checkContinue'`][] event on `Http2Server` and `Http2SecureServer`. -### `response.writeEarlyHints(links)` +#### `response.writeEarlyHints(hints)` <!-- YAML added: v18.11.0 --> -* `links` {string|Array} +* `hints` {Object} Sends a status `103 Early Hints` to the client with a Link header, indicating that the user agent can preload/preconnect the linked resources. -The `links` can be a string or an array of strings containing the values -of the `Link` header. +The `hints` is an object containing the values of headers to be sent with +early hints message. **Example** ```js const earlyHintsLink = '</styles.css>; rel=preload; as=style'; -response.writeEarlyHints(earlyHintsLink); +response.writeEarlyHints({ + 'link': earlyHintsLink, +}); const earlyHintsLinks = [ '</styles.css>; rel=preload; as=style', '</scripts.js>; rel=preload; as=script', ]; -response.writeEarlyHints(earlyHintsLinks); +response.writeEarlyHints({ + 'link': earlyHintsLinks, +}); ``` #### `response.writeHead(statusCode[, statusMessage][, headers])` |