Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 72ad2c9

Browse files
koichikisaacs
authored andcommitted
https: fix default port
https.get('https://github.com/') should use port 443, not 80.
1 parent 32fdae2 commit 72ad2c9

3 files changed

Lines changed: 88 additions & 25 deletions

File tree

lib/_http_client.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ function ClientRequest(options, cb) {
4444
var self = this;
4545
OutgoingMessage.call(self);
4646

47+
options = util._extend({}, options);
48+
4749
self.agent = util.isUndefined(options.agent) ? globalAgent : options.agent;
4850

49-
var defaultPort = options.defaultPort || 80;
51+
var defaultPort = options.defaultPort || self.agent.defaultPort;
5052

51-
var port = options.port || defaultPort;
52-
var host = options.hostname || options.host || 'localhost';
53+
var port = options.port = options.port || defaultPort;
54+
var host = options.host = options.hostname || options.host || 'localhost';
5355

5456
if (util.isUndefined(options.setHost)) {
5557
var setHost = true;

test/disabled/test-http-default-port.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121

2222

2323

24-
25-
// This must be run as root.
26-
2724
var common = require('../common');
2825
var http = require('http'),
2926
https = require('https'),
30-
PORT = 80,
31-
SSLPORT = 443,
27+
PORT = common.PORT,
28+
SSLPORT = common.PORT + 1,
3229
assert = require('assert'),
3330
hostExpect = 'localhost',
3431
fs = require('fs'),
@@ -37,32 +34,52 @@ var http = require('http'),
3734
options = {
3835
key: fs.readFileSync(fixtures + '/agent1-key.pem'),
3936
cert: fs.readFileSync(fixtures + '/agent1-cert.pem')
40-
};
37+
},
38+
gotHttpsResp = false,
39+
gotHttpResp = false;
40+
41+
process.on('exit', function() {
42+
assert(gotHttpsResp);
43+
assert(gotHttpResp);
44+
console.log('ok');
45+
});
46+
47+
http.globalAgent.defaultPort = PORT;
48+
https.globalAgent.defaultPort = SSLPORT;
4149

4250
http.createServer(function(req, res) {
43-
console.error(req.headers);
4451
assert.equal(req.headers.host, hostExpect);
52+
assert.equal(req.headers['x-port'], PORT);
4553
res.writeHead(200);
4654
res.end('ok');
4755
this.close();
48-
}).listen(PORT);
56+
}).listen(PORT, function() {
57+
http.get({
58+
host: 'localhost',
59+
headers: {
60+
'x-port': PORT
61+
}
62+
}, function(res) {
63+
gotHttpResp = true;
64+
res.resume();
65+
});
66+
});
4967

5068
https.createServer(options, function(req, res) {
51-
console.error(req.headers);
5269
assert.equal(req.headers.host, hostExpect);
70+
assert.equal(req.headers['x-port'], SSLPORT);
5371
res.writeHead(200);
5472
res.end('ok');
5573
this.close();
56-
}).listen(SSLPORT);
57-
58-
http
59-
.get({ host: 'localhost',
60-
port: PORT,
61-
headers: { 'x-port': PORT } })
62-
.on('response', function(res) {});
63-
64-
https
65-
.get({ host: 'localhost',
66-
port: SSLPORT,
67-
headers: { 'x-port': SSLPORT } })
68-
.on('response', function(res) {});
74+
}).listen(SSLPORT, function() {
75+
var req = https.get({
76+
host: 'localhost',
77+
rejectUnauthorized: false,
78+
headers: {
79+
'x-port': SSLPORT
80+
}
81+
}, function(res) {
82+
gotHttpsResp = true;
83+
res.resume();
84+
});
85+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var common = require('../common');
23+
var assert = require('assert');
24+
25+
var https = require('https');
26+
var http = require('http');
27+
var gotHttpsResp = false;
28+
var gotHttpResp = false;
29+
30+
process.on('exit', function() {
31+
assert(gotHttpsResp);
32+
assert(gotHttpResp);
33+
console.log('ok');
34+
});
35+
36+
https.get('https://www.google.com/', function(res) {
37+
gotHttpsResp = true;
38+
res.resume();
39+
});
40+
41+
http.get('http://www.google.com/', function(res) {
42+
gotHttpResp = true;
43+
res.resume();
44+
});

0 commit comments

Comments
 (0)