Skip to content

Commit a441be1

Browse files
author
Adam Mcgrath
committed
Fix http proxy with https server
1 parent 25ee9bd commit a441be1

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/webpagetest.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,30 @@ var filenames = {
5757

5858
// GET helper function
5959
function get(config, pathname, proxy, callback, encoding) {
60-
var protocol = (config.protocol === 'https:' ? https : http),
60+
var protocol,
6161
options;
6262

6363
if (proxy) {
64+
var proxyUrl = url.parse(proxy);
6465
var pathForProxy = config.protocol + '//';
6566

6667
if (config.auth) {
6768
pathForProxy += config.auth + '@';
6869
}
6970

7071
pathForProxy += config.hostname + ':' + config.port + pathname;
72+
protocol = (proxyUrl.protocol === 'https:' ? https : http);
7173

7274
options = {
73-
host: proxy.split(':')[0],
74-
port: proxy.split(':')[1],
75+
host: proxyUrl.hostname,
76+
port: proxyUrl.port,
7577
path: pathForProxy,
7678
headers: {
7779
Host: config.hostname
7880
}
7981
};
8082
} else {
83+
protocol = (config.protocol === 'https:' ? https : http);
8184
options = {
8285
path: pathname,
8386
host: config.hostname,

test/proxy-test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
var assert = require('assert'),
99
http = require('http'),
10+
https = require('https'),
1011
url = require('url'),
1112
WebPageTest = require('../lib/webpagetest'),
1213
NockServer = require('./helpers/nock-server'),
1314
ResponseObjects = require('./helpers/response-objects');
1415

15-
var wptNockServer = new NockServer('http://wpt.com'),
16-
wpt = new WebPageTest('wpt.com');
16+
var wptNockServer = new NockServer('https://wpt.com'),
17+
wpt = new WebPageTest('https://wpt.com');
1718

1819
// proxy for test on 9001 port
1920
http.createServer(function(req, res) {
@@ -24,7 +25,7 @@ http.createServer(function(req, res) {
2425
body.push(data);
2526
});
2627
req.on('end', function() {
27-
var orgreq = http.request({
28+
var orgreq = https.request({
2829
host: req.headers.host,
2930
port: requestUrl.port || 80,
3031
path: requestUrl.path,
@@ -52,7 +53,7 @@ describe('Run via proxy', function() {
5253

5354
it('gets a test status request', function(done) {
5455
wpt.getTestStatus('120816_V2_2', {
55-
proxy: '127.0.0.1:9001'
56+
proxy: 'http://127.0.0.1:9001'
5657
}, function (err, data) {
5758
if (err) return done(err);
5859
assert.deepEqual(data, ResponseObjects.testStatus);

0 commit comments

Comments
 (0)