Skip to content

Commit 5fbccae

Browse files
meyfaRafaelGSS
authored andcommitted
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: #45000 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent a27c994 commit 5fbccae

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

doc/api/http.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,9 @@ response.writeEarlyHints({
21752175
});
21762176

21772177
const earlyHintsCallback = () => console.log('early hints message sent');
2178-
response.writeEarlyHints(earlyHintsLinks, earlyHintsCallback);
2178+
response.writeEarlyHints({
2179+
'link': earlyHintsLinks,
2180+
}, earlyHintsCallback);
21792181
```
21802182

21812183
### `response.writeHead(statusCode[, statusMessage][, headers])`

doc/api/http2.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -3787,7 +3787,7 @@ Removes a header that has been queued for implicit sending.
37873787
response.removeHeader('Content-Encoding');
37883788
```
37893789

3790-
### `response.req`
3790+
#### `response.req`
37913791

37923792
<!-- YAML
37933793
added: v15.7.0
@@ -4005,30 +4005,34 @@ Sends a status `100 Continue` to the client, indicating that the request body
40054005
should be sent. See the [`'checkContinue'`][] event on `Http2Server` and
40064006
`Http2SecureServer`.
40074007

4008-
### `response.writeEarlyHints(links)`
4008+
#### `response.writeEarlyHints(hints)`
40094009

40104010
<!-- YAML
40114011
added: v18.11.0
40124012
-->
40134013

4014-
* `links` {string|Array}
4014+
* `hints` {Object}
40154015

40164016
Sends a status `103 Early Hints` to the client with a Link header,
40174017
indicating that the user agent can preload/preconnect the linked resources.
4018-
The `links` can be a string or an array of strings containing the values
4019-
of the `Link` header.
4018+
The `hints` is an object containing the values of headers to be sent with
4019+
early hints message.
40204020

40214021
**Example**
40224022

40234023
```js
40244024
const earlyHintsLink = '</styles.css>; rel=preload; as=style';
4025-
response.writeEarlyHints(earlyHintsLink);
4025+
response.writeEarlyHints({
4026+
'link': earlyHintsLink,
4027+
});
40264028

40274029
const earlyHintsLinks = [
40284030
'</styles.css>; rel=preload; as=style',
40294031
'</scripts.js>; rel=preload; as=script',
40304032
];
4031-
response.writeEarlyHints(earlyHintsLinks);
4033+
response.writeEarlyHints({
4034+
'link': earlyHintsLinks,
4035+
});
40324036
```
40334037

40344038
#### `response.writeHead(statusCode[, statusMessage][, headers])`

0 commit comments

Comments
 (0)