• 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, sending back :status 100, writing the rest of
13// the request to finally the client receiving to.
14
15const server = http2.createServer();
16
17let sentResponse = false;
18
19server.on('request', common.mustCall((req, res) => {
20  res.end(testResBody);
21  sentResponse = true;
22}));
23
24server.listen(0);
25
26server.on('listening', common.mustCall(() => {
27  let body = '';
28
29  const client = http2.connect(`http://localhost:${server.address().port}`);
30  const req = client.request({
31    ':method': 'POST',
32    'expect': '100-continue'
33  });
34
35  let gotContinue = false;
36  req.on('continue', common.mustCall(() => {
37    gotContinue = true;
38  }));
39
40  req.on('response', common.mustCall((headers) => {
41    assert.strictEqual(gotContinue, true);
42    assert.strictEqual(sentResponse, true);
43    assert.strictEqual(headers[':status'], 200);
44    req.end();
45  }));
46
47  req.setEncoding('utf8');
48  req.on('data', common.mustCall((chunk) => { body += chunk; }));
49  req.on('end', common.mustCall(() => {
50    assert.strictEqual(body, testResBody);
51    client.close();
52    server.close();
53  }));
54}));
55