• 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 h2 = require('http2');
8
9// Requests using host instead of :authority should be allowed
10// and Http2ServerRequest.authority should fall back to host
11
12// :authority should NOT be auto-filled if host is present
13
14const server = h2.createServer();
15server.listen(0, common.mustCall(function() {
16  const port = server.address().port;
17  server.once('request', common.mustCall(function(request, response) {
18    const expected = {
19      ':path': '/foobar',
20      ':method': 'GET',
21      ':scheme': 'http',
22      'host': `localhost:${port}`
23    };
24
25    assert.strictEqual(request.authority, expected.host);
26
27    const headers = request.headers;
28    for (const [name, value] of Object.entries(expected)) {
29      assert.strictEqual(headers[name], value);
30    }
31
32    const rawHeaders = request.rawHeaders;
33    for (const [name, value] of Object.entries(expected)) {
34      const position = rawHeaders.indexOf(name);
35      assert.notStrictEqual(position, -1);
36      assert.strictEqual(rawHeaders[position + 1], value);
37    }
38
39    assert(!Object.hasOwn(headers, ':authority'));
40    assert(!Object.hasOwn(rawHeaders, ':authority'));
41
42    response.on('finish', common.mustCall(function() {
43      server.close();
44    }));
45    response.end();
46  }));
47
48  const url = `http://localhost:${port}`;
49  const client = h2.connect(url, common.mustCall(function() {
50    const headers = {
51      ':path': '/foobar',
52      ':method': 'GET',
53      ':scheme': 'http',
54      'host': `localhost:${port}`
55    };
56    const request = client.request(headers);
57    request.on('end', common.mustCall(function() {
58      client.close();
59    }));
60    request.end();
61    request.resume();
62  }));
63}));
64