Comparing version 1.5.3 to 1.6.1
111
httpntlm.js
'use strict'; | ||
var async = require('async'); | ||
var url = require('url'); | ||
@@ -8,4 +7,6 @@ var httpreq = require('httpreq'); | ||
var _ = require('underscore'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
exports.method = function(method, options, callback){ | ||
exports.method = function(method, options, finalCallback){ | ||
if(!options.workstation) options.workstation = ''; | ||
@@ -26,62 +27,76 @@ if(!options.domain) options.domain = ''; | ||
if(isHttps){ | ||
var HttpsAgent = require('agentkeepalive').HttpsAgent; | ||
keepaliveAgent = new HttpsAgent(); | ||
keepaliveAgent = new https.Agent({keepAlive: true}); | ||
}else{ | ||
var Agent = require('agentkeepalive'); | ||
keepaliveAgent = new Agent(); | ||
keepaliveAgent = new http.Agent({keepAlive: true}); | ||
} | ||
async.waterfall([ | ||
function ($){ | ||
var type1msg = ntlm.createType1Message(options); | ||
// build type1 request: | ||
// build type1 request: | ||
var type1options = { | ||
headers:{ | ||
'Connection' : 'keep-alive', | ||
'Authorization': type1msg | ||
}, | ||
timeout: options.timeout || 0, | ||
agent: keepaliveAgent | ||
}; | ||
function sendType1Message (callback) { | ||
var type1msg = ntlm.createType1Message(options); | ||
// pass along timeout and ca: | ||
if(httpreqOptions.timeout) type1options.timeout = httpreqOptions.timeout; | ||
if(httpreqOptions.ca) type1options.ca = httpreqOptions.ca; | ||
var type1options = { | ||
headers:{ | ||
'Connection' : 'keep-alive', | ||
'Authorization': type1msg | ||
}, | ||
timeout: options.timeout || 0, | ||
agent: keepaliveAgent, | ||
allowRedirects: false // don't redirect in httpreq, because http could change to https which means we need to change the keepaliveAgent | ||
}; | ||
// send type1 message to server: | ||
httpreq.get(options.url, type1options, $); | ||
}, | ||
// pass along timeout and ca: | ||
if(httpreqOptions.timeout) type1options.timeout = httpreqOptions.timeout; | ||
if(httpreqOptions.ca) type1options.ca = httpreqOptions.ca; | ||
function (res, $){ | ||
if(!res.headers['www-authenticate']) | ||
return $(new Error('www-authenticate not found on response of second request')); | ||
// send type1 message to server: | ||
httpreq.get(options.url, type1options, callback); | ||
} | ||
// parse type2 message from server: | ||
var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']); | ||
function sendType3Message (res, callback) { | ||
// catch redirect here: | ||
if(res.headers.location) { | ||
options.url = res.headers.location; | ||
return exports[method](options, finalCallback); | ||
} | ||
// create type3 message: | ||
var type3msg = ntlm.createType3Message(type2msg, options); | ||
// build type3 request: | ||
var type3options = { | ||
headers: { | ||
'Connection': 'Close', | ||
'Authorization': type3msg | ||
}, | ||
allowRedirects: false, | ||
agent: keepaliveAgent | ||
}; | ||
if(!res.headers['www-authenticate']) | ||
return callback(new Error('www-authenticate not found on response of second request')); | ||
// pass along other options: | ||
type3options.headers = _.extend(type3options.headers, httpreqOptions.headers); | ||
type3options = _.extend(type3options, _.omit(httpreqOptions, 'headers')); | ||
// parse type2 message from server: | ||
var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']); | ||
// send type3 message to server: | ||
httpreq[method](options.url, type3options, $); | ||
} | ||
], callback); | ||
// 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 finalCallback(err); | ||
setImmediate(function () { // doesn't work without setImmediate() | ||
sendType3Message(res, finalCallback); | ||
}); | ||
}); | ||
}; | ||
['get', 'put', 'post', 'delete'].forEach(function(method){ | ||
['get', 'put', 'patch', 'post', 'delete', 'options'].forEach(function(method){ | ||
exports[method] = exports.method.bind(exports, method); | ||
@@ -88,0 +103,0 @@ }); |
{ | ||
"name": "httpntlm", | ||
"description": "httpntlm is a Node.js library to do HTTP NTLM authentication", | ||
"version": "1.5.3", | ||
"version": "1.6.1", | ||
"dependencies": { | ||
"agentkeepalive": ">=1.2.0", | ||
"async": "~0.2.9", | ||
"httpreq": ">=0.4.5", | ||
"httpreq": ">=0.4.22", | ||
"underscore": "~1.7.0" | ||
@@ -19,3 +17,3 @@ }, | ||
"engines": { | ||
"node": ">=0.11.0" | ||
"node": ">=0.8.0" | ||
}, | ||
@@ -22,0 +20,0 @@ "repository": { |
@@ -83,10 +83,12 @@ # httpntlm | ||
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); | ||
}); | ||
} | ||
@@ -101,2 +103,21 @@ ], function (err, res) { | ||
## Download binary files | ||
```javascript | ||
httpntlm.get({ | ||
url: "https://someurl.com/file.xls", | ||
username: 'm$', | ||
password: 'stinks', | ||
workstation: 'choose.something', | ||
domain: '', | ||
binary: true | ||
}, function (err, response) { | ||
if(err) return console.log(err); | ||
fs.writeFile("file.xls", response.body, function (err) { | ||
if(err) return console.log("error writing file"); | ||
console.log("file.xls saved!"); | ||
}); | ||
}); | ||
``` | ||
## More information | ||
@@ -103,0 +124,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23957
2
395
149
3
- Removedagentkeepalive@>=1.2.0
- Removedasync@~0.2.9
- Removedagentkeepalive@4.5.0(transitive)
- Removedasync@0.2.10(transitive)
- Removedhumanize-ms@1.2.1(transitive)
- Removedms@2.1.3(transitive)
Updatedhttpreq@>=0.4.22