Skip to content
Browse files

Merge pull request #102 from fzaninotto/https_redirect

Fix redirection from https to http
  • Loading branch information...
2 parents 141e2d8 + 6df1ced commit afc03561f368a85018306a241e7b80e949053d79 @fzaninotto committed Jan 30, 2013
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/pollers/https.js
View
18 lib/pollers/https.js
@@ -4,6 +4,7 @@
var util = require('util');
var https = require('https');
+var http = require('http');
var url = require('url');
var BasePoller = require('./base');
@@ -48,9 +49,14 @@ HttpsPoller.prototype.setUserAgent = function(userAgent) {
*
* @api public
*/
-HttpsPoller.prototype.poll = function() {
+HttpsPoller.prototype.poll = function(secure) {
HttpsPoller.super_.prototype.poll.call(this);
- this.request = https.get(this.target, this.onResponseCallback.bind(this));
+ secure = typeof secure !== 'undefined' ? secure : true;
+ if (secure) {
+ this.request = https.get(this.target, this.onResponseCallback.bind(this));
+ } else {
+ this.request = http.get(this.target, this.onResponseCallback.bind(this));
+ }
this.request.on('error', this.onErrorCallback.bind(this));
};
@@ -72,13 +78,17 @@ HttpsPoller.prototype.onResponseCallback = function(res) {
if (!target.protocol) {
// relative location header. This is incorrect but tolerated
this.target = url.parse('http://' + this.target.hostname + res.headers.location);
- this.poll();
+ this.poll(false);
return;
}
switch (target.protocol) {
case 'https:':
this.target = target;
- this.poll();
+ this.poll(true);
+ break;
+ case 'http:':
+ this.target = target;
+ this.poll(false);
break;
default:
this.request.abort();

0 comments on commit afc0356

Please sign in to comment.
Something went wrong with that request. Please try again.