Skip to content

Commit 3a57b11

Browse files
committed
test: actually check req.trailers null prototype in http-server-headers-null-proto
1 parent 8c7c040 commit 3a57b11

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

doc/api/http.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,9 @@ The request/response headers object.
28632863

28642864
Key-value pairs of header names and values. Header names are lower-cased.
28652865

2866+
The object has a null prototype and should not be accessed using the `in`
2867+
operator.
2868+
28662869
```js
28672870
// Prints something like:
28682871
//
@@ -2900,6 +2903,9 @@ added:
29002903
Similar to [`message.headers`][], but there is no join logic and the values are
29012904
always arrays of strings, even for headers received just once.
29022905

2906+
The object has a null prototype and should not be accessed using the `in`
2907+
operator.
2908+
29032909
```js
29042910
// Prints something like:
29052911
//
@@ -3086,6 +3092,9 @@ added: v0.3.0
30863092

30873093
The request/response trailers object. Only populated at the `'end'` event.
30883094

3095+
The object has a null prototype and should not be accessed using the `in`
3096+
operator.
3097+
30893098
### `message.trailersDistinct`
30903099

30913100
<!-- YAML
@@ -3100,6 +3109,9 @@ Similar to [`message.trailers`][], but there is no join logic and the values are
31003109
always arrays of strings, even for headers received just once.
31013110
Only populated at the `'end'` event.
31023111

3112+
The object has a null prototype and should not be accessed using the `in`
3113+
operator.
3114+
31033115
### `message.url`
31043116

31053117
<!-- YAML

doc/api/http2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,9 @@ The request/response headers object.
41204120

41214121
Key-value pairs of header names and values. Header names are lower-cased.
41224122

4123+
The object has a null prototype and should not be accessed using the `in`
4124+
operator.
4125+
41234126
```js
41244127
// Prints something like:
41254128
//
@@ -4279,6 +4282,9 @@ added: v8.4.0
42794282

42804283
The request/response trailers object. Only populated at the `'end'` event.
42814284

4285+
The object has a null prototype and should not be accessed using the `in`
4286+
operator.
4287+
42824288
#### `request.url`
42834289

42844290
<!-- YAML

test/parallel/test-http-server-headers-null-proto.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ const net = require('net');
3535
// Test 2: req.trailers has a null prototype
3636
{
3737
const server = http.createServer(common.mustCall((req, res) => {
38+
req.on('end', common.mustCall(() => {
39+
assert.strictEqual(Object.getPrototypeOf(req.trailers), null);
40+
assert.strictEqual(req.trailers['x-client-trailer'], 'bar');
41+
}));
3842
res.setHeader('Transfer-Encoding', 'chunked');
43+
res.setHeader('Trailer', 'X-Trailer');
3944
res.write('Hello');
4045
res.addTrailers({
4146
'X-Trailer': 'test',
@@ -50,8 +55,12 @@ const net = require('net');
5055
client.write(
5156
'GET / HTTP/1.1\r\n' +
5257
'Host: localhost\r\n' +
53-
'TE: trailers\r\n' +
58+
'Transfer-Encoding: chunked\r\n' +
59+
'Trailer: X-Client-Trailer\r\n' +
5460
'Connection: close\r\n' +
61+
'\r\n' +
62+
'0\r\n' +
63+
'X-Client-Trailer: bar\r\n' +
5564
'\r\n',
5665
);
5766
}));

0 commit comments

Comments
 (0)