Closed
Description
- Version: master with http2: Introducing http/2 #14239
- Platform: Windows 7 x 64
- Subsystem: http2
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:
The first two is the Server, the last two are Client requests and they are trying to connect the 443 port.