-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-http-server-de-chunked-trailer.js
More file actions
38 lines (35 loc) · 1.11 KB
/
test-http-server-de-chunked-trailer.js
File metadata and controls
38 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const common = require('../common');
// This test ensures that a Trailer header is set only when a chunked transfer
// encoding is used.
const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer(common.mustCall(function(req, res) {
res.setHeader('Trailer', 'baz');
const trailerInvalidErr = {
code: 'ERR_HTTP_TRAILER_INVALID',
message: 'Trailers are invalid with this transfer encoding',
type: Error
};
common.expectsError(() => res.writeHead(200, { 'Content-Length': '2' }),
trailerInvalidErr);
res.removeHeader('Trailer');
res.end('ok');
}));
server.listen(0, common.mustCall(() => {
const client = http2.connect('http://localhost:' + server.address().port);
const req = client.request();
req.end();
req.on('response', common.mustCall((res)=>{
assert.strictEqual(res[':status'], 200);
let buf = '';
req.on('data', (chunk) => {
buf += chunk;
}).on('end', common.mustCall(() => {
assert.strictEqual(buf, 'ok');
req.close();
client.close();
}));
server.close();
}));
}));