• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6const assert = require('assert');
7const http2 = require('http2');
8
9const expectValue = 'meoww';
10
11const server = http2.createServer(common.mustNotCall());
12
13server.once('checkExpectation', common.mustCall((req, res) => {
14  assert.strictEqual(req.headers.expect, expectValue);
15  res.statusCode = 417;
16  res.end();
17}));
18
19server.listen(0, common.mustCall(() => nextTest(2)));
20
21function nextTest(testsToRun) {
22  if (!testsToRun) {
23    return server.close();
24  }
25
26  const port = server.address().port;
27  const client = http2.connect(`http://localhost:${port}`);
28  const req = client.request({
29    ':path': '/',
30    ':method': 'GET',
31    ':scheme': 'http',
32    ':authority': `localhost:${port}`,
33    'expect': expectValue
34  });
35
36  req.on('response', common.mustCall((headers) => {
37    assert.strictEqual(headers[':status'], 417);
38    req.resume();
39  }));
40
41  req.on('end', common.mustCall(() => {
42    client.close();
43    nextTest(testsToRun - 1);
44  }));
45}
46