• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Spec documentation http://httpwg.github.io/specs/rfc7231.html#header.expect
2'use strict';
3const common = require('../common');
4const assert = require('assert');
5const http = require('http');
6
7const tests = [417, 417];
8
9let testsComplete = 0;
10let testIdx = 0;
11
12const s = http.createServer((req, res) => {
13  throw new Error('this should never be executed');
14});
15
16s.listen(0, nextTest);
17
18function nextTest() {
19  const options = {
20    port: s.address().port,
21    headers: { 'Expect': 'meoww' }
22  };
23
24  if (testIdx === tests.length) {
25    return s.close();
26  }
27
28  const test = tests[testIdx];
29
30  if (testIdx > 0) {
31    s.on('checkExpectation', common.mustCall((req, res) => {
32      res.statusCode = 417;
33      res.end();
34    }));
35  }
36
37  http.get(options, (response) => {
38    console.log(`client: expected status: ${test}`);
39    console.log(`client: statusCode: ${response.statusCode}`);
40    assert.strictEqual(response.statusCode, test);
41    assert.strictEqual(response.statusMessage, 'Expectation Failed');
42
43    response.on('end', () => {
44      testsComplete++;
45      testIdx++;
46      nextTest();
47    });
48    response.resume();
49  });
50}
51
52
53process.on('exit', () => {
54  assert.strictEqual(testsComplete, 2);
55});
56