Skip to content

Commit

Permalink
Merge pull request #108 from laurentdebricon/patch-1
Browse files Browse the repository at this point in the history
Activate user agent spoofing while still be able to use setUserAgent("my agent just for a request")
  • Loading branch information
chriso committed Jun 19, 2012
2 parents 650942a + 8aa8003 commit da0039d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/node.io/request.js
Expand Up @@ -234,6 +234,11 @@ Job.prototype.doRequest = function (method, resource, body, headers, callback, p


//Copy `headers` before modifying it //Copy `headers` before modifying it
headers = utils.put({}, headers); headers = utils.put({}, headers);

//Set a random user agent if using --spoof
if (this.options.spoof) {
headers['user-agent'] = user_agents[Math.floor(Math.random() * user_agents.length)];
}


//Add headers from a previous request if this is a nested request //Add headers from a previous request if this is a nested request
if (this.last.headers) { if (this.last.headers) {
Expand All @@ -244,11 +249,6 @@ Job.prototype.doRequest = function (method, resource, body, headers, callback, p
utils.put(headers, this.next); utils.put(headers, this.next);
this.next = {}; this.next = {};


//Set a random user agent if using --spoof
if (this.options.spoof) {
headers['user-agent'] = user_agents[Math.floor(Math.random() * user_agents.length)];
}

//Prepare the body to write and get the content length //Prepare the body to write and get the content length
if (body) { if (body) {
if (typeof body === 'object') { if (typeof body === 'object') {
Expand Down

0 comments on commit da0039d

Please sign in to comment.