-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-http2-respond-with-file-connection-abort.js
More file actions
37 lines (32 loc) · 1 KB
/
test-http2-respond-with-file-connection-abort.js
File metadata and controls
37 lines (32 loc) · 1 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
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const net = require('net');
const {
HTTP2_HEADER_CONTENT_TYPE
} = http2.constants;
const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
stream.on('error', common.mustCallAtLeast((err) => {
assert.ok(
err.code === 'ECONNRESET' || err.code === 'ERR_HTTP2_STREAM_ERROR',
`Unexpected error code: ${err.code}`
);
}, 0));
stream.respondWithFile(process.execPath, {
[HTTP2_HEADER_CONTENT_TYPE]: 'application/octet-stream'
});
}));
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
req.on('error', common.mustCall());
req.on('response', common.mustCall());
req.once('data', common.mustCall(() => {
net.Socket.prototype.destroy.call(client.socket);
server.close();
}));
}));