summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-header-badrequest.js
blob: 8294ca9fe208ec9c9f4f389340f8e6b133417e2e (plain)
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
'use strict';
const { mustCall } = require('../common');
const assert = require('assert');
const { createServer } = require('http');
const { createConnection } = require('net');

const server = createServer();

server.on('request', mustCall((req, res) => {
  res.write('asd', () => {
    res.socket.emit('error', new Error('kaboom'));
  });
}));

server.listen(0, mustCall(() => {
  const c = createConnection(server.address().port);
  let received = '';

  c.on('connect', mustCall(() => {
    c.write('GET /blah HTTP/1.1\r\n\r\n');
  }));
  c.on('data', mustCall((data) => {
    received += data.toString();
  }));
  c.on('end', mustCall(() => {
    // Should not include anything else after asd.
    assert.strictEqual(received.indexOf('asd\r\n'), received.length - 5);
    c.end();
  }));
  c.on('close', mustCall(() => server.close()));
}));