Skip to content

Commit e5f9a52

Browse files
meyfadanielleadams
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 1ed312a commit e5f9a52

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
@@ -2162,7 +2162,9 @@ response.writeEarlyHints({
21622162
});
21632163

21642164
const earlyHintsCallback = () => console.log('early hints message sent');
2165-
response.writeEarlyHints(earlyHintsLinks, earlyHintsCallback);
2165+
response.writeEarlyHints({
2166+
'link': earlyHintsLinks,
2167+
}, earlyHintsCallback);
21662168
```
21672169

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

doc/api/http2.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -3773,7 +3773,7 @@ Removes a header that has been queued for implicit sending.
37733773
response.removeHeader('Content-Encoding');
37743774
```
37753775

3776-
### `response.req`
3776+
#### `response.req`
37773777

37783778
<!-- YAML
37793779
added: v15.7.0
@@ -3991,30 +3991,34 @@ Sends a status `100 Continue` to the client, indicating that the request body
39913991
should be sent. See the [`'checkContinue'`][] event on `Http2Server` and
39923992
`Http2SecureServer`.
39933993

3994-
### `response.writeEarlyHints(links)`
3994+
#### `response.writeEarlyHints(hints)`
39953995

39963996
<!-- YAML
39973997
added: v18.11.0
39983998
-->
39993999

4000-
* `links` {string|Array}
4000+
* `hints` {Object}
40014001

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

40074007
**Example**
40084008

40094009
```js
40104010
const earlyHintsLink = '</styles.css>; rel=preload; as=style';
4011-
response.writeEarlyHints(earlyHintsLink);
4011+
response.writeEarlyHints({
4012+
'link': earlyHintsLink,
4013+
});
40124014

40134015
const earlyHintsLinks = [
40144016
'</styles.css>; rel=preload; as=style',
40154017
'</scripts.js>; rel=preload; as=script',
40164018
];
4017-
response.writeEarlyHints(earlyHintsLinks);
4019+
response.writeEarlyHints({
4020+
'link': earlyHintsLinks,
4021+
});
40184022
```
40194023

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

0 commit comments

Comments
 (0)