Socket
Socket
Sign inDemoInstall

request-debug

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-debug - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

26

index.js
var clone = require('clone');
var debugId = 0;
module.exports = exports = function(request, log) {

@@ -24,6 +26,7 @@ log = log || exports.log;

proto.init = function() {
if (!this._debugHandlersAdded) {
if (!this._debugId) {
this.on('request', function(req) {
var obj = {
var data = {
debugId : this._debugId,
uri : this.uri.href,

@@ -34,5 +37,5 @@ method : this.method,

if (this.body) {
obj.body = this.body.toString('utf8');
data.body = this.body.toString('utf8');
}
log('request', obj);
log('request', data, this);

@@ -46,5 +49,6 @@ }).on('response', function(res) {

log('response', {
debugId : this._debugId,
headers : clone(res.headers),
statusCode : res.statusCode
});
}, this);
}

@@ -55,6 +59,7 @@

log('response', {
debugId : this._debugId,
headers : clone(res.headers),
statusCode : res.statusCode,
body : res.body
});
}, this);
}

@@ -65,9 +70,10 @@

log(type, {
debugId : this._debugId,
statusCode : this.response.statusCode,
headers : clone(this.response.headers),
uri : this.uri.href
});
}, this);
});
this._debugHandlersAdded = true;
this._debugId = ++debugId;
}

@@ -87,6 +93,6 @@

exports.log = function(type, obj) {
exports.log = function(type, data, r) {
var toLog = {};
toLog[type] = obj;
toLog[type] = data;
console.error(toLog);
};

@@ -5,3 +5,3 @@ {

"description" : "Library to assist with debugging HTTP(s) requests made by the request module.",
"version" : "0.0.3",
"version" : "0.1.0",
"repository" : {

@@ -8,0 +8,0 @@ "type" : "git",

# request-debug [![Build status](https://img.shields.io/travis/nylen/request-debug.svg?style=flat)](https://travis-ci.org/nylen/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 debug HTTP(S) requests performed by
the [`request` module](https://github.com/mikeal/request), and their responses
from external servers.
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
responses from external servers.

@@ -24,3 +24,3 @@ ## Usage

```js
require('request-debug')(request, function(type, data) {
require('request-debug')(request, function(type, data, r) {
// put your request or response handling logic here

@@ -30,3 +30,4 @@ });

If you specify your own handling function, `type` will be one of the following values:
If you specify your own handling function, `r` will be the `Request` instance
that generated the event, and `type` will be one of the following values:

@@ -49,5 +50,8 @@ - **request** - Headers were sent to the server and will be included as

The default handling function writes the data to *stderr* in Node's JSON-like object
display format. See the example below for more details.
You can use the `data.debugId` parameter to match up requests with their
responses and other events.
The default handling function writes the data to *stderr* in Node's JSON-like
object display format. See the example below for more details.
To disable debugging, call `request.stopDebugging()` (this function only exists

@@ -86,12 +90,14 @@ if debugging has already been enabled). Any requests that are in progress when

{ request:
{ uri: 'http://nylen.tv/digest.php',
{ debugId: 1,
uri: 'http://nylen.tv/digest.php',
method: 'GET',
headers: { host: 'nylen.tv' } } }
{ auth:
{ statusCode: 401,
{ debugId: 1,
statusCode: 401,
headers:
{ date: 'Fri, 29 Aug 2014 00:10:11 GMT',
{ date: 'Mon, 20 Oct 2014 03:34:58 GMT',
server: 'Apache/2.4.6 (Debian)',
'x-powered-by': 'PHP/5.5.6-1',
'www-authenticate': 'Digest realm="Restricted area",qop="auth",nonce="53ffc4e3f308e",opaque="cdce8a5c95a1427d74df7acbf41c9ce0"',
'www-authenticate': 'Digest realm="Restricted area",qop="auth",nonce="544482e2556d9",opaque="cdce8a5c95a1427d74df7acbf41c9ce0"',
'content-length': '39',

@@ -103,10 +109,12 @@ 'keep-alive': 'timeout=5, max=100',

{ request:
{ uri: 'http://nylen.tv/digest.php',
{ debugId: 1,
uri: 'http://nylen.tv/digest.php',
method: 'GET',
headers:
{ authorization: 'Digest username="admin", realm="Restricted area", nonce="53ffc4e3f308e", uri="/digest.php", qop=auth, response="d7c6bf1c2657228e146da3edf034a419", nc=00000001, cnonce="4fa4a6af3d1d424397cb2c798d5a97df", opaque="cdce8a5c95a1427d74df7acbf41c9ce0"',
{ 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:
{ headers:
{ date: 'Fri, 29 Aug 2014 00:10:12 GMT',
{ debugId: 1,
headers:
{ date: 'Mon, 20 Oct 2014 03:34:58 GMT',
server: 'Apache/2.4.6 (Debian)',

@@ -120,3 +128,3 @@ 'x-powered-by': 'PHP/5.5.6-1',

body: 'You are logged in as: admin' } }
REQUEST RESULTS: null 200 'You are logged in as: admin'
REQUEST RESULTS: null 200 You are logged in as: admin
```

@@ -126,5 +134,6 @@

Tested with Node.js versions 0.8.x, 0.10.x, and 0.11.x on Travis.
Tested with Node.js versions 0.8.x, 0.10.x, and 0.11.x on Travis, and a bunch
of different `request` versions.
Does not work with `request` versions older than 2.22.0 (July 2013). Tests
don't start passing until version 2.28.0 (December 2013).

@@ -32,2 +32,3 @@ var lib = require('./lib'),

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -41,2 +42,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -66,2 +68,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -75,2 +78,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -99,2 +103,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/middle',

@@ -108,2 +113,3 @@ method : 'GET',

redirect : {
debugId : lib.debugId,
headers : {

@@ -123,2 +129,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -132,2 +139,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -157,2 +165,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.https + '/middle/http',

@@ -166,2 +175,3 @@ method : 'GET',

redirect : {
debugId : lib.debugId,
headers : {

@@ -181,2 +191,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -190,2 +201,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -221,2 +233,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/auth/bottom',

@@ -230,2 +243,3 @@ method : 'GET',

auth : {
debugId : lib.debugId,
headers : {

@@ -243,2 +257,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/auth/bottom',

@@ -253,2 +268,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -284,2 +300,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.https + '/auth/top/http',

@@ -293,2 +310,3 @@ method : 'GET',

auth : {
debugId : lib.debugId,
headers : {

@@ -306,2 +324,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.https + '/auth/top/http',

@@ -316,2 +335,3 @@ method : 'GET',

redirect : {
debugId : lib.debugId,
headers : {

@@ -331,2 +351,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/middle',

@@ -341,2 +362,3 @@ method : 'GET',

redirect : {
debugId : lib.debugId,
headers : {

@@ -356,2 +378,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -366,2 +389,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -397,2 +421,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -409,2 +434,3 @@ method : 'POST',

response : {
debugId : lib.debugId,
headers : {

@@ -436,2 +462,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -446,2 +473,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -485,2 +513,3 @@ connection : '<close or keep-alive>',

request : {
debugId : lib.debugId,
uri : lib.urls.http + '/bottom',

@@ -494,2 +523,3 @@ method : 'GET',

response : {
debugId : lib.debugId,
headers : {

@@ -496,0 +526,0 @@ connection : '<close or keep-alive>',

@@ -21,2 +21,3 @@ var express = require('express'),

exports.urls = {};
exports.debugId = 0;

@@ -32,6 +33,9 @@ for (var proto in ports) {

// enable debugging
require('../..')(request, function(type, data) {
require('../..')(request, function(type, data, r) {
var obj = {};
obj[type] = data;
exports.requests.push(obj);
if (typeof r._initBeforeDebug != 'function') {
throw new Error('Expected a Request instance here.');
}
});

@@ -42,2 +46,3 @@ };

exports.requests = [];
exports.debugId++;
};

@@ -44,0 +49,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc