Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions http-digest-client.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ var HTTPDigest = function () {
var crypto = require('crypto');
var http = require('http');

var HTTPDigest = function (username, password, https) {
var HTTPDigest = function (host, port, username, password, https) {
this.nc = 0;
this.username = username;
this.password = password;
this.host = host;
this.port = port;
if(https === true) {
http = require('https');
}
Expand All @@ -25,11 +27,33 @@ var HTTPDigest = function () {
//
HTTPDigest.prototype.request = function (options, callback) {
var self = this;
http.request(options, function (res) {
options['host'] = this.host;
options['port'] = this.port;
self.client = http.request(options, function (res) {
self._handleResponse(options, res, callback);
}).end();
});

if(options['method'] == 'GET'){
self.client.end();
}
else if(options['method'] == 'POST')
{
self.client.write(options['data']);
self.end();
}
};

HTTPDigest.prototype.on = function(event, callthis){
this.client.on(event, callthis);
}

HTTPDigest.prototype.write = function(data){
this.client.write(data);
}

HTTPDigest.prototype.end = function(){
this.client.end();
}
//
// ## Handle authentication
//
Expand Down Expand Up @@ -86,10 +110,13 @@ var HTTPDigest = function () {
var headers = options.headers || {};
headers.Authorization = this._compileParams(authParams);
options.headers = headers;

http.request(options, function (res) {
this.client = http.request(options, function (res) {
callback(res);
}).end();
});
if(options['method']=='POST'){
this.client.write(options['data']);
}
this.client.end();
};

//
Expand All @@ -107,7 +134,6 @@ var HTTPDigest = function () {
params[part[1]] = part[2];
}
}

return params;
};

Expand Down Expand Up @@ -140,7 +166,7 @@ var HTTPDigest = function () {
return HTTPDigest;
}();

module.exports = function createDigestClient(username, password, https) {
return new HTTPDigest(username, password, https);
module.exports = function createDigestClient(host, port, username, password, https) {
return new HTTPDigest(host, port, username, password, https);
};