Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vsemozhetbyt opened this issue Jul 16, 2017 · 6 comments
Closed

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

vsemozhetbyt opened this issue Jul 16, 2017 · 6 comments
Labels
doc Issues and PRs related to the documentations. http2 Issues or PRs related to the http2 subsystem.

Comments

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jul 16, 2017

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.

@vsemozhetbyt vsemozhetbyt added doc Issues and PRs related to the documentations. http2 Issues or PRs related to the http2 subsystem. labels Jul 16, 2017
@jasnell
Copy link
Member

jasnell commented Jul 17, 2017

Will look into it! Thank you! :-)

@apapirovski
Copy link
Member

ping @vsemozhetbyt — is this still the case for you?

@vsemozhetbyt
Copy link
Contributor Author

@apapirovski Yes, the behavior from the first post remains with Node.js 8.7.0 or the last nightly build.

@apapirovski
Copy link
Member

@vsemozhetbyt Could you try the same with http or net when you have a moment?

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Oct 19, 2017

@apapirovski Let me know if I use wrong test examples.
Server:

'use strict';

const http = require('http');

const hostname = 'localhost';
const port = 81;

const server = http.createServer((req, res) => {
  console.log(req.headers);

  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Client:

'use strict';

const http = require('http');

http.get({
  hostname: 'localhost',
  port: 81,
  path: '/',
}, (res) => {
  console.log(res.headers);
});

Port 81, Server:

Server running at http://localhost:81/
{ host: 'localhost:81', connection: 'close' }

Port 81, Client:

{ 'content-type': 'text/plain',
  date: 'Thu, 19 Oct 2017 12:30:28 GMT',
  connection: 'close',
  'content-length': '12' }

Port 80, Server:

Server running at http://localhost:80/
{ host: 'localhost', connection: 'close' }

Port 80, Client:

{ 'content-type': 'text/plain',
  date: 'Thu, 19 Oct 2017 12:31:35 GMT',
  connection: 'close',
  'content-length': '12' }

@apapirovski
Copy link
Member

Thanks so much for testing http too! I think I have a rough lead on what's going on. Will update later tonight when I have a moment to confirm whether I'm right or not.

apapirovski added a commit to apapirovski/node that referenced this issue Oct 23, 2017
Due to how WHATWG-URL parser works, port numbers are omitted if
they are the default port for a scheme. This meant that
http2.connect could not accept connections on port 80 with http
scheme. Fix this bug by detecting http: scheme and setting port
to 80.

Fixes: nodejs#14304
MylesBorins pushed a commit that referenced this issue Oct 23, 2017
Due to how WHATWG-URL parser works, port numbers are omitted if
they are the default port for a scheme. This meant that
http2.connect could not accept connections on port 80 with http
scheme. Fix this bug by detecting http: scheme and setting port
to 80.

PR-URL: #16337
Fixes: #14304
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this issue Oct 26, 2017
Due to how WHATWG-URL parser works, port numbers are omitted if
they are the default port for a scheme. This meant that
http2.connect could not accept connections on port 80 with http
scheme. Fix this bug by detecting http: scheme and setting port
to 80.

PR-URL: nodejs/node#16337
Fixes: nodejs/node#14304
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this issue Dec 7, 2017
Due to how WHATWG-URL parser works, port numbers are omitted if
they are the default port for a scheme. This meant that
http2.connect could not accept connections on port 80 with http
scheme. Fix this bug by detecting http: scheme and setting port
to 80.

PR-URL: nodejs/node#16337
Fixes: nodejs/node#14304
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. http2 Issues or PRs related to the http2 subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants