From f7e7b3064e4c91739d2db104f2d57425903dc66a Mon Sep 17 00:00:00 2001 From: James Lamanna Date: Thu, 11 Sep 2014 15:49:11 +0000 Subject: [PATCH] Provide callback for posting data to the request object --- http-digest-client.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/http-digest-client.js b/http-digest-client.js index 12d0d16..a6b4e5b 100644 --- a/http-digest-client.js +++ b/http-digest-client.js @@ -23,10 +23,15 @@ var HTTPDigest = function () { // // Wraps the http.request function to apply digest authorization. // - HTTPDigest.prototype.request = function (options, callback) { + HTTPDigest.prototype.request = function (options, callback, requestCallback) { var self = this; http.request(options, function (res) { - self._handleResponse(options, res, callback); + var req = self._handleResponse(options, res, callback); + if (requestCallback) { + requestCallback(req); + } else { + req.end(); + } }).end(); }; @@ -87,9 +92,7 @@ var HTTPDigest = function () { headers.Authorization = this._compileParams(authParams); options.headers = headers; - http.request(options, function (res) { - callback(res); - }).end(); + return http.request(options, function (res) { callback(res); }); }; // @@ -140,7 +143,10 @@ var HTTPDigest = function () { return HTTPDigest; }(); -module.exports = function createDigestClient(username, password, https) { - return new HTTPDigest(username, password, https); +module.exports = { + createDigestClient: function(username, password, https) { + return new HTTPDigest(username, password, https); + } }; +// vim: set ts=2 sw=2 et: