From 8c74500c3d9fc01d73bf91a7c347c985ee5c1cb2 Mon Sep 17 00:00:00 2001 From: Saurabh Wahile Date: Sat, 27 Jun 2015 14:15:05 +0530 Subject: [PATCH 1/2] Moved host & port to constructor --- http-digest-client.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/http-digest-client.js b/http-digest-client.js index 12d0d16..8ba498e 100644 --- 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,6 +27,8 @@ var HTTPDigest = function () { // HTTPDigest.prototype.request = function (options, callback) { var self = this; + options['host'] = this.host; + options['port'] = this.port; http.request(options, function (res) { self._handleResponse(options, res, callback); }).end(); @@ -140,7 +144,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); }; From 57e17b763b8bfe1455ac0dc63c8e61e09e8e0187 Mon Sep 17 00:00:00 2001 From: Saurabh Wahile Date: Thu, 2 Jul 2015 00:14:47 +0530 Subject: [PATCH 2/2] Added POST support --- http-digest-client.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) mode change 100644 => 100755 http-digest-client.js diff --git a/http-digest-client.js b/http-digest-client.js old mode 100644 new mode 100755 index 8ba498e..39acc78 --- a/http-digest-client.js +++ b/http-digest-client.js @@ -29,11 +29,31 @@ var HTTPDigest = function () { var self = this; options['host'] = this.host; options['port'] = this.port; - http.request(options, function (res) { + 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 // @@ -90,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(); }; // @@ -111,7 +134,6 @@ var HTTPDigest = function () { params[part[1]] = part[2]; } } - return params; }; @@ -144,7 +166,7 @@ var HTTPDigest = function () { return HTTPDigest; }(); -module.exports= function createDigestClient(host, port, username, password, https) { +module.exports = function createDigestClient(host, port, username, password, https) { return new HTTPDigest(host, port, username, password, https); };