Skip to content

Commit 745e7c4

Browse files
committed
[js] Use https.request() for https requests.
Fixes #1897
1 parent c554cf3 commit 745e7c4

File tree

1 file changed

+9
-3
lines changed
  • javascript/node/selenium-webdriver/http

1 file changed

+9
-3
lines changed

javascript/node/selenium-webdriver/http/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'use strict';
2424

2525
const http = require('http');
26+
const https = require('https');
2627
const url = require('url');
2728

2829
const cmd = require('../lib/command');
@@ -233,13 +234,15 @@ class HttpClient {
233234
* @private {{auth: (?string|undefined),
234235
* host: string,
235236
* path: (?string|undefined),
236-
* port: (?string|undefined)}}
237+
* port: (?string|undefined),
238+
* protocol: (?string|undefined)}}
237239
*/
238240
this.options_ = {
239241
auth: parsedUrl.auth,
240242
host: parsedUrl.hostname,
241243
path: parsedUrl.pathname,
242-
port: parsedUrl.port
244+
port: parsedUrl.port,
245+
protocol: parsedUrl.protocol
243246
};
244247
}
245248

@@ -279,6 +282,7 @@ class HttpClient {
279282
auth: this.options_.auth,
280283
host: this.options_.host,
281284
port: this.options_.port,
285+
protocol: this.options_.protocol,
282286
path: path,
283287
headers: headers
284288
};
@@ -321,7 +325,8 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy) {
321325
}
322326
}
323327

324-
var request = http.request(options, function(response) {
328+
let requestFn = options.protocol === 'https:' ? https.request : http.request;
329+
var request = requestFn(options, function onResponse(response) {
325330
if (response.statusCode == 302 || response.statusCode == 303) {
326331
try {
327332
var location = url.parse(response.headers['location']);
@@ -344,6 +349,7 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy) {
344349
host: location.hostname,
345350
path: location.pathname + (location.search || ''),
346351
port: location.port,
352+
protocol: location.protocol,
347353
headers: {
348354
'Accept': 'application/json; charset=utf-8'
349355
}

0 commit comments

Comments
 (0)