Skip to content

Commit

Permalink
[js] Use https.request() for https requests.
Browse files Browse the repository at this point in the history
Fixes #1897
  • Loading branch information
jleyba committed Jun 28, 2016
1 parent 4a33bf9 commit 32f59a3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions javascript/node/selenium-webdriver/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'use strict';

const http = require('http');
const https = require('https');
const url = require('url');

const cmd = require('../lib/command');
Expand Down Expand Up @@ -233,13 +234,15 @@ class HttpClient {
* @private {{auth: (?string|undefined),
* host: string,
* path: (?string|undefined),
* port: (?string|undefined)}}
* port: (?string|undefined),
* protocol: (?string|undefined)}}
*/
this.options_ = {
auth: parsedUrl.auth,
host: parsedUrl.hostname,
path: parsedUrl.pathname,
port: parsedUrl.port
port: parsedUrl.port,
protocol: parsedUrl.protocol
};
}

Expand Down Expand Up @@ -279,6 +282,7 @@ class HttpClient {
auth: this.options_.auth,
host: this.options_.host,
port: this.options_.port,
protocol: this.options_.protocol,
path: path,
headers: headers
};
Expand Down Expand Up @@ -321,7 +325,8 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy) {
}
}

var request = http.request(options, function(response) {
let requestFn = options.protocol === 'https:' ? https.request : http.request;
var request = requestFn(options, function onResponse(response) {
if (response.statusCode == 302 || response.statusCode == 303) {
try {
var location = url.parse(response.headers['location']);
Expand All @@ -344,6 +349,7 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy) {
host: location.hostname,
path: location.pathname + (location.search || ''),
port: location.port,
protocol: location.protocol,
headers: {
'Accept': 'application/json; charset=utf-8'
}
Expand Down

0 comments on commit 32f59a3

Please sign in to comment.