diff --git a/http-digest-client.js b/http-digest-client.js old mode 100644 new mode 100755 index 12d0d16..39acc78 --- a/http-digest-client.js +++ b/http-digest-client.js @@ -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'); } @@ -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 // @@ -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(); }; // @@ -107,7 +134,6 @@ var HTTPDigest = function () { params[part[1]] = part[2]; } } - return params; }; @@ -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); };