• 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 testResBody = 'other stuff!\n';
10
11// Checks the full 100-continue flow from client sending 'expect: 100-continue'
12// through server receiving it, triggering 'checkContinue' custom handler,
13// writing the rest of the request to finally the client receiving to.
14
15const server = http2.createServer(
16  common.mustNotCall('Full request received before 100 Continue')
17);
18
19server.on('checkContinue', common.mustCall((req, res) => {
20  res.writeContinue();
21  res.writeHead(200, {});
22  res.end(testResBody);
23  // Should simply return false if already too late to write
24  assert.strictEqual(res.writeContinue(), false);
25  res.on('finish', common.mustCall(
26    () => process.nextTick(() => assert.strictEqual(res.writeContinue(), false))
27  ));
28}));
29
30server.listen(0, common.mustCall(() => {
31  let body = '';
32
33  const client = http2.connect(`http://localhost:${server.address().port}`);
34  const req = client.request({
35    ':method': 'POST',
36    'expect': '100-continue'
37  });
38
39  let gotContinue = false;
40  req.on('continue', common.mustCall(() => {
41    gotContinue = true;
42  }));
43
44  req.on('response', common.mustCall((headers) => {
45    assert.strictEqual(gotContinue, true);
46    assert.strictEqual(headers[':status'], 200);
47    req.end();
48  }));
49
50  req.setEncoding('utf-8');
51  req.on('data', common.mustCall((chunk) => { body += chunk; }));
52
53  req.on('end', common.mustCall(() => {
54    assert.strictEqual(body, testResBody);
55    client.close();
56    server.close();
57  }));
58}));
59