From 2b43b285d00fa76905e8d1f5a210a3c612edcd44 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Thu, 30 Apr 2015 11:48:44 -0400 Subject: [PATCH 1/5] drop `clone` module in favor of `JSON.parse` & `JSON.stringify` combo for better performance --- README.md | 16 ++++++++-------- index.js | 10 ++++------ package.json | 4 +--- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 1a80f7b..4bffbbc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # request-debug [![Build status](https://img.shields.io/travis/request/request-debug.svg?style=flat)](https://travis-ci.org/request/request-debug) [![npm package](http://img.shields.io/npm/v/request-debug.svg?style=flat)](https://www.npmjs.org/package/request-debug) This Node.js module provides an easy way to monitor HTTP(S) requests performed -by the [`request` module](https://github.com/mikeal/request), and their +by the [`request` module](https://github.com/request/request), and their responses from external servers. ## Usage @@ -83,15 +83,15 @@ Unless you provide your own function as the second parameter to the following: ```js -{ request: +{ request: { debugId: 1, uri: 'http://nylen.tv/digest.php', method: 'GET', headers: { host: 'nylen.tv' } } } -{ auth: +{ auth: { debugId: 1, statusCode: 401, - headers: + headers: { date: 'Mon, 20 Oct 2014 03:34:58 GMT', server: 'Apache/2.4.6 (Debian)', 'x-powered-by': 'PHP/5.5.6-1', @@ -101,16 +101,16 @@ following: connection: 'Keep-Alive', 'content-type': 'text/html' }, uri: 'http://nylen.tv/digest.php' } } -{ request: +{ request: { debugId: 1, uri: 'http://nylen.tv/digest.php', method: 'GET', - headers: + headers: { authorization: 'Digest username="admin", realm="Restricted area", nonce="544482e2556d9", uri="/digest.php", qop=auth, response="e833c7fa52e8d42fae3ca784b96dfd38", nc=00000001, cnonce="ab6ff3dd95a0449e990a6c8465a6bb26", opaque="cdce8a5c95a1427d74df7acbf41c9ce0"', host: 'nylen.tv' } } } -{ response: +{ response: { debugId: 1, - headers: + headers: { date: 'Mon, 20 Oct 2014 03:34:58 GMT', server: 'Apache/2.4.6 (Debian)', 'x-powered-by': 'PHP/5.5.6-1', diff --git a/index.js b/index.js index f6db0cd..be68ae1 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,3 @@ -var clone = require('clone'); - var debugId = 0; module.exports = exports = function(request, log) { @@ -30,7 +28,7 @@ module.exports = exports = function(request, log) { debugId : this._debugId, uri : this.uri.href, method : this.method, - headers : clone(this.headers) + headers : JSON.parse(JSON.stringify(this.headers)) }; if (this.body) { data.body = this.body.toString('utf8'); @@ -45,7 +43,7 @@ module.exports = exports = function(request, log) { // cannot get body since no callback specified log('response', { debugId : this._debugId, - headers : clone(res.headers), + headers : JSON.parse(JSON.stringify(res.headers)), statusCode : res.statusCode }, this); } @@ -54,7 +52,7 @@ module.exports = exports = function(request, log) { if (this.callback) { log('response', { debugId : this._debugId, - headers : clone(res.headers), + headers : JSON.parse(JSON.stringify(res.headers)), statusCode : res.statusCode, body : res.body }, this); @@ -65,7 +63,7 @@ module.exports = exports = function(request, log) { log(type, { debugId : this._debugId, statusCode : this.response.statusCode, - headers : clone(this.response.headers), + headers : JSON.parse(JSON.stringify(this.response.headers)), uri : this.uri.href }, this); }); diff --git a/package.json b/package.json index eb2aa51..051a398 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,5 @@ "request" : "~2.40.0", "should" : "~4.0.4" }, - "dependencies" : { - "clone" : "~0.1.18" - } + "dependencies" : {} } From 0aab79c0a80e25bc794cf5fc90813440fdf0917e Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Fri, 1 May 2015 11:54:40 -0400 Subject: [PATCH 2/5] use a wrapper for JSON.stringify --- index.js | 10 ++++++---- package.json | 13 +++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index be68ae1..4522648 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +var clone = require('stringify-clone'); + var debugId = 0; module.exports = exports = function(request, log) { @@ -28,7 +30,7 @@ module.exports = exports = function(request, log) { debugId : this._debugId, uri : this.uri.href, method : this.method, - headers : JSON.parse(JSON.stringify(this.headers)) + headers : clone(this.headers) }; if (this.body) { data.body = this.body.toString('utf8'); @@ -43,7 +45,7 @@ module.exports = exports = function(request, log) { // cannot get body since no callback specified log('response', { debugId : this._debugId, - headers : JSON.parse(JSON.stringify(res.headers)), + headers : clone(res.headers), statusCode : res.statusCode }, this); } @@ -52,7 +54,7 @@ module.exports = exports = function(request, log) { if (this.callback) { log('response', { debugId : this._debugId, - headers : JSON.parse(JSON.stringify(res.headers)), + headers : clone(res.headers), statusCode : res.statusCode, body : res.body }, this); @@ -63,7 +65,7 @@ module.exports = exports = function(request, log) { log(type, { debugId : this._debugId, statusCode : this.response.statusCode, - headers : JSON.parse(JSON.stringify(this.response.headers)), + headers : clone(this.response.headers), uri : this.uri.href }, this); }); diff --git a/package.json b/package.json index 051a398..9690b02 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,13 @@ }, "main" : "index.js", "devDependencies" : { - "express" : "~4.8.6", - "mocha" : "~1.21.4", - "passport" : "~0.2.0", - "passport-http" : "~0.2.2", - "request" : "~2.40.0", - "should" : "~4.0.4" + "express" : "~4.8.6", + "mocha" : "~1.21.4", + "passport" : "~0.2.0", + "passport-http" : "~0.2.2", + "request" : "~2.40.0", + "should" : "~4.0.4", + "stringify-clone": "^1.0.0" }, "dependencies" : {} } From d356cec2b6a7f2fa7ddb747ef83c05c85db0b324 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Fri, 1 May 2015 12:19:33 -0400 Subject: [PATCH 3/5] stringify-clone should be a dependency (not a devDependency) --- package.json | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9690b02..daf6e67 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,14 @@ }, "main" : "index.js", "devDependencies" : { - "express" : "~4.8.6", - "mocha" : "~1.21.4", - "passport" : "~0.2.0", - "passport-http" : "~0.2.2", - "request" : "~2.40.0", - "should" : "~4.0.4", - "stringify-clone": "^1.0.0" + "express" : "~4.8.6", + "mocha" : "~1.21.4", + "passport" : "~0.2.0", + "passport-http" : "~0.2.2", + "request" : "~2.40.0", + "should" : "~4.0.4" }, - "dependencies" : {} + "dependencies" : { + "stringify-clone": "^1.0.0" + } } From afd2d830582ee6d86a7d14b3490e0a2eb80068da Mon Sep 17 00:00:00 2001 From: simov Date: Wed, 20 May 2015 20:52:21 +0300 Subject: [PATCH 4/5] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ede765..933eda0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name" : "request-debug", "author" : "James Nylen ", "description" : "Library to assist with debugging HTTP(s) requests made by the request module.", - "version" : "0.1.1", + "version" : "0.2.0", "repository" : { "type" : "git", "url" : "https://github.com/request/request-debug" From c6f247d4e2c73a5549d40d426fbf7b0233638968 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 26 May 2015 15:38:53 +0300 Subject: [PATCH 5/5] Use container-based infrastructure --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index bae5bb5..135f2ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,5 @@ env: before_script: - rm -r node_modules/request/ - npm install request@$REQUEST_VERSION + +sudo: false