Skip to content

Commit

Permalink
add response Truncate limit to truncate large responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmedfcis committed Jul 7, 2023
1 parent 8994155 commit c403e4a
Show file tree
Hide file tree
Showing 3 changed files with 6,395 additions and 17 deletions.
18 changes: 16 additions & 2 deletions lib/run/summary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var _ = require('lodash'),
sdk = require('postman-collection'),
SerialiseError = require('serialised-error'),
RunSummary;
RunSummary,
_responseTruncateLimit = Infinity;

/**
* Creates and returns a RunSummary instance for the current collection run.
Expand All @@ -14,6 +15,9 @@ RunSummary = function RunSummary (emitter, options) {
// keep a copy of this instance since, we need to refer to this from various events
var summary = this;

// Set responseTruncateLimit
_responseTruncateLimit = _.get(options, 'responseTruncateLimit', _responseTruncateLimit);

// and store the trackers and failures in the summary object itself
_.assign(summary, /** @lends RunSummary.prototype */ {
/**
Expand Down Expand Up @@ -225,10 +229,20 @@ _.assign(RunSummary, {

var execution = cache[o.cursor.ref] = (cache[o.cursor.ref] || {});

// Copy response object
let response = {};

_.assign(response, o.response);

// Truncate large response body
if (_.get(response, 'stream') && response.stream.length > _responseTruncateLimit) {
response.stream = response.stream.slice(0, _responseTruncateLimit);
}

executions.push(_.assignIn(execution, {
cursor: o.cursor,
request: o.request,
response: o.response,
response: response,
id: _.get(o, 'item.id')
}, err && {
requestError: err || undefined
Expand Down
Loading

0 comments on commit c403e4a

Please sign in to comment.