Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Don't send along an '<unavailable>' body for GET/HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Nov 5, 2015
1 parent 08bb6c5 commit 0476a6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
14 changes: 11 additions & 3 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@ module.exports.parseRequest = function parseRequest(req, kwargs) {
// express: req.body
// koa: req.body
//
var data = req.body || '<unavailable>';
// Make sure the request body is a string
if ( {}.toString.call(data) !== '[object String]' ) data = JSON.stringify(data);
var data = req.body;
if (['GET', 'HEAD'].indexOf(method) === -1) {
if (typeof data === 'undefined') {
data = '<unavailable>';
}
}

if (data && {}.toString.call(data) !== '[object String]') {
// Make sure the request body is a string
data = JSON.stringify(data);
}

// client ip:
//
Expand Down
17 changes: 14 additions & 3 deletions test/raven.parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,33 @@ describe('raven.parsers', function(){

it('should fallback to <unavailable> if body is not available', function(){
var mockReq = {
method: 'GET',
method: 'POST',
hostname: 'mattrobenolt.com',
url: '/some/path?key=value',
body: ''
};

var parsed = raven.parsers.parseRequest(mockReq);

parsed['request'].data.should.equal('<unavailable>');
});

it('should make sure that body is a string', function(){
it('should not fallback to <unavailable> if GET', function(){
var mockReq = {
method: 'GET',
hostname: 'mattrobenolt.com',
url: '/some/path?key=value',
};

var parsed = raven.parsers.parseRequest(mockReq);

(typeof parsed['request'].data === 'undefined').should.be.ok;
});

it('should make sure that body is a string', function(){
var mockReq = {
method: 'POST',
hostname: 'mattrobenolt.com',
url: '/some/path?key=value',
body: {'foo': true}
};

Expand Down

0 comments on commit 0476a6e

Please sign in to comment.