GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: Corrects IPv6 address in Host header · nodejs/node@b28e44d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • _http_client.js
  • test/parallel
    • test-http-host-header-ipv6-fail.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ function ClientRequest(options, cb) {
8181
}
8282
if (host && !this.getHeader('host') && setHost) {
8383
var hostHeader = host;
84+
var posColon = -1;
85+
86+
// For the Host header, ensure that IPv6 addresses are enclosed
87+
// in square brackets, as defined by URI formatting
88+
// https://tools.ietf.org/html/rfc3986#section-3.2.2
89+
if (-1 !== (posColon = hostHeader.indexOf(':')) &&
90+
-1 !== (posColon = hostHeader.indexOf(':', posColon)) &&
91+
'[' !== hostHeader[0]) {
92+
hostHeader = `[${hostHeader}]`;
93+
}
94+
8495
if (port && +port !== defaultPort) {
8596
hostHeader += ':' + port;
8697
}
Collapse file

‎test/parallel/test-http-host-header-ipv6-fail.js‎

Copy file name to clipboard
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
/*
3+
* When using the object form of http.request and using an IPv6 address
4+
* as a hostname, and using a non-standard port, the Host header
5+
* is improperly formatted.
6+
* Issue: https://github.com/nodejs/node/issues/5308
7+
* As per https://tools.ietf.org/html/rfc7230#section-5.4 and
8+
* https://tools.ietf.org/html/rfc3986#section-3.2.2
9+
* the IPv6 address should be enclosed in square brackets
10+
*/
11+
12+
const common = require('../common');
13+
const assert = require('assert');
14+
const http = require('http');
15+
16+
const hostname = '::1';
17+
const port = common.PORT;
18+
19+
function httpreq() {
20+
var req = http.request({
21+
host: hostname,
22+
port: port,
23+
path: '/',
24+
method: 'GET'
25+
});
26+
req.end();
27+
}
28+
29+
if (!common.hasIPv6) {
30+
console.error('Skipping test, no IPv6 support');
31+
return;
32+
}
33+
34+
const server = http.createServer(common.mustCall(function(req, res) {
35+
assert.ok(req.headers.host, `[${hostname}]`);
36+
res.end();
37+
server.close(true);
38+
}));
39+
40+
server.listen(port, hostname, () => httpreq());

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.