Skip to content

http2: code examples does not work on Windows with port 80 #14304

Description

@vsemozhetbyt

Refs: #14239 (http2.md)

The first examples from "Core API" chapter do not work properly on Windows with port 80 but work with other ports.

I've added some output and repeated request for easier debugging. Here are the code and output with port 81:

Server:

const http2 = require('http2');

// Create a plain-text HTTP/2 server
const server = http2.createServer();

server.on('stream', (stream, headers) => {
  console.log('headers: ', headers);
  stream.respond({
    'content-type': 'text/html',
    ':status': 200
  });
  stream.end('<h1>Hello World</h1>');
});

server.listen(81);

Client:

const http2 = require('http2');

function test() {
  const client = http2.connect('http://localhost:81');

  const req = client.request({ ':path': '/' });

  req.on('response', (headers) => {
    console.log(headers[':status']);
    console.log(headers['date']);
  });

  let data = '';
  req.setEncoding('utf8');
  req.on('data', (d) => data += d);
  req.on('end', () => { client.destroy(); console.log('data: ', data); });
  req.end();
}

setInterval(test, 2000);

Server output:

(node:7960) ExperimentalWarning: The http2 module is an experimental API.
headers:  { ':scheme': 'http',
  ':authority': 'localhost:81',
  ':method': 'GET',
  ':path': '/' }
headers:  { ':scheme': 'http',
  ':authority': 'localhost:81',
  ':method': 'GET',
  ':path': '/' }
headers:  { ':scheme': 'http',
  ':authority': 'localhost:81',
  ':method': 'GET',
  ':path': '/' }

Client output:

(node:6732) ExperimentalWarning: The http2 module is an experimental API.
200
Sun, 16 Jul 2017 13:40:19 GMT
data:  <h1>Hello World</h1>
200
Sun, 16 Jul 2017 13:40:21 GMT
data:  <h1>Hello World</h1>
200
Sun, 16 Jul 2017 13:40:23 GMT
data:  <h1>Hello World</h1>

When I change the port in both examples into 80, I get:
Server output:

(node:4792) ExperimentalWarning: The http2 module is an experimental API.

Client output:

(node:1784) ExperimentalWarning: The http2 module is an experimental API.
data:
data:
data:

FWIW, I've tried to see what was going on with TCPView:
http2
The first two is the Server, the last two are Client requests and they are trying to connect the 443 port.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.http2Issues and PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions