• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const { mustCall } = require('../common');
3const assert = require('assert');
4const http = require('http');
5const net = require('net');
6
7// https://github.com/nodejs/node/issues/17789 - a connection upgrade response
8// that has a Transfer-Encoding header and a body whose first byte is > 127
9// triggers a bug where said byte is skipped over.
10net.createServer(mustCall(function(conn) {
11  conn.write('HTTP/1.1 101 Switching Protocols\r\n' +
12             'Connection: upgrade\r\n' +
13             'Transfer-Encoding: chunked\r\n' +
14             'Upgrade: websocket\r\n' +
15             '\r\n' +
16             '\u0080', 'latin1');
17  this.close();
18})).listen(0, mustCall(function() {
19  http.get({
20    host: this.address().host,
21    port: this.address().port,
22    headers: { 'Connection': 'upgrade', 'Upgrade': 'websocket' },
23  }).on('upgrade', mustCall((res, conn, head) => {
24    assert.strictEqual(head.length, 1);
25    assert.strictEqual(head[0], 128);
26    conn.destroy();
27  }));
28}));
29