Skip to content
This repository was archived by the owner on Feb 13, 2018. It is now read-only.

Commit bdcf145

Browse files
author
Tim Whitlock
committed
Merge pull request #1 from atorres757/master
Added the ability to use a proxy when making requests
2 parents 8b8a6fb + 2aefdc8 commit bdcf145

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/twitter.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ function TwitterClient(){
162162
this.deAuth();
163163
}
164164

165+
TwitterClient.prototype.setProxy = function(proxy) {
166+
this.proxy = proxy;
167+
}
168+
165169
TwitterClient.prototype.getLastMeta = function( method ){
166170
return this.lastMeta[ method || this.lastCall ] || { limit: 0, remaining: 0, reset: 0 };
167171
}
@@ -348,6 +352,17 @@ TwitterClient.prototype._call = function( requestMethod, requestUri, requestArgs
348352
else if( query ){
349353
http.path += '?' + query;
350354
}
355+
// configure proxy
356+
if (typeof this.proxy == "object") {
357+
if (typeof this.proxy.host != "undefined") {
358+
http.host = this.proxy.host;
359+
http.path = "https://" + http.hostname + http.path;
360+
delete http.hostname;
361+
}
362+
if (typeof this.proxy.port != "undefined") {
363+
http.port = this.proxy.port;
364+
}
365+
}
351366
var req = require('https').get( http, callback );
352367
if( timeout ){
353368
req.on('socket', function (socket) {

0 commit comments

Comments
 (0)