Skip to content

Commit

Permalink
removed async dependency, fixed issue #30
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDecrock committed May 2, 2016
1 parent c366bd5 commit ae14803
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ results

npm-debug.log
node_modules
app.js
app.js
test.js
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ async.waterfall([
var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']);
var type3msg = ntlm.createType3Message(type2msg, options);

httpreq.get(options.url, {
headers:{
'Connection' : 'Close',
'Authorization': type3msg
},
allowRedirects: false,
agent: keepaliveAgent
}, callback);
setImmediate(function() {
httpreq.get(options.url, {
headers:{
'Connection' : 'Close',
'Authorization': type3msg
},
allowRedirects: false,
agent: keepaliveAgent
}, callback);
});
}
], function (err, res) {
if(err) return console.log(err);
Expand Down
109 changes: 58 additions & 51 deletions httpntlm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var async = require('async');
var url = require('url');
var httpreq = require('httpreq');
var ntlm = require('./ntlm');
Expand Down Expand Up @@ -29,56 +28,64 @@ exports.method = function(method, options, callback){
keepaliveAgent = new http.Agent({keepAlive: true});
}

async.waterfall([
function ($){
var type1msg = ntlm.createType1Message(options);

// build type1 request:
var type1options = {
headers:{
'Connection' : 'keep-alive',
'Authorization': type1msg
},
timeout: options.timeout || 0,
agent: keepaliveAgent
};

// pass along timeout and ca:
if(httpreqOptions.timeout) type1options.timeout = httpreqOptions.timeout;
if(httpreqOptions.ca) type1options.ca = httpreqOptions.ca;

// send type1 message to server:
httpreq.get(options.url, type1options, $);
},

function (res, $){
if(!res.headers['www-authenticate'])
return $(new Error('www-authenticate not found on response of second request'));

// parse type2 message from server:
var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']);

// create type3 message:
var type3msg = ntlm.createType3Message(type2msg, options);

// build type3 request:
var type3options = {
headers: {
'Connection': 'Close',
'Authorization': type3msg
},
allowRedirects: false,
agent: keepaliveAgent
};

// pass along other options:
type3options.headers = _.extend(type3options.headers, httpreqOptions.headers);
type3options = _.extend(type3options, _.omit(httpreqOptions, 'headers'));

// send type3 message to server:
httpreq[method](options.url, type3options, $);
}
], callback);
// build type1 request:

function sendType1Message (callback) {
var type1msg = ntlm.createType1Message(options);

var type1options = {
headers:{
'Connection' : 'keep-alive',
'Authorization': type1msg
},
timeout: options.timeout || 0,
agent: keepaliveAgent
};

// pass along timeout and ca:
if(httpreqOptions.timeout) type1options.timeout = httpreqOptions.timeout;
if(httpreqOptions.ca) type1options.ca = httpreqOptions.ca;

// send type1 message to server:
httpreq.get(options.url, type1options, callback);
}

function sendType3Message (res, callback) {
if(!res.headers['www-authenticate'])
return $(new Error('www-authenticate not found on response of second request'));

// parse type2 message from server:
var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']);

// create type3 message:
var type3msg = ntlm.createType3Message(type2msg, options);

// build type3 request:
var type3options = {
headers: {
'Connection': 'Close',
'Authorization': type3msg
},
allowRedirects: false,
agent: keepaliveAgent
};

// pass along other options:
type3options.headers = _.extend(type3options.headers, httpreqOptions.headers);
type3options = _.extend(type3options, _.omit(httpreqOptions, 'headers'));

// send type3 message to server:
httpreq[method](options.url, type3options, callback);
}


sendType1Message(function (err, res) {
if(err) return callback(err);
setImmediate(function () { // doesn't work without setImmediate()
sendType3Message(res, callback);
});
});

};

['get', 'put', 'patch', 'post', 'delete', 'options'].forEach(function(method){
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "httpntlm",
"description": "httpntlm is a Node.js library to do HTTP NTLM authentication",
"version": "1.5.3",
"version": "1.6.0",
"dependencies": {
"async": "~0.2.9",
"httpreq": ">=0.4.22",
"underscore": "~1.7.0"
},
Expand Down

0 comments on commit ae14803

Please sign in to comment.