From 4e0dfd9de4fc8de91c08d0a8af218f4d2a1d3681 Mon Sep 17 00:00:00 2001 From: Fabian Meyer <3982806+meyfa@users.noreply.github.com> Date: Mon, 17 Oct 2022 15:57:28 +0100 Subject: [PATCH] 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 Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: Rafael Gonzaga --- doc/api/http.md | 4 +++- 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 9144f8aec7f3bf..3675329d0cbbe6 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -2162,7 +2162,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 0964c91e4e0f60..d7af2b47f237f4 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -3773,7 +3773,7 @@ Removes a header that has been queued for implicit sending. response.removeHeader('Content-Encoding'); ``` -### `response.req` +#### `response.req` -* `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 = '; rel=preload; as=style'; -response.writeEarlyHints(earlyHintsLink); +response.writeEarlyHints({ + 'link': earlyHintsLink, +}); const earlyHintsLinks = [ '; rel=preload; as=style', '; rel=preload; as=script', ]; -response.writeEarlyHints(earlyHintsLinks); +response.writeEarlyHints({ + 'link': earlyHintsLinks, +}); ``` #### `response.writeHead(statusCode[, statusMessage][, headers])`