catchpoint/WebPageTest.api-nodejs

getResponseBody code to load by bodyid

dimension85 opened this issue · 0 comments

The API interface works fine if you know the request number, but the html body is easier to identify by the bodyid tag, which is not supported by the current API.

The following is an update to the getResponseBody code the enables both request and bodyid as options

function getResponseBody(id, options, callback) {
// WSI Mod - enables any parm to be parsed eg bodyid
var query;
let temp = options ; // WSI Mod - addition of temp
callback = callback || options;
options = options === callback ? {} : options;
options.args = options.args || {type: 'text/plain'};
query = setFilename({test: id}, options);
query.request = options.request || 1;

let merged = {};						//	WSI Mod - addition of temp obj	
Object.assign(merged, query, temp);		//	WSI Mod - merge original and new options
query = merged ;						//	WSI Mod - reload query

return api.call(this, paths.responseBody, callback, query, options);

}

Nothing else changes except in the call options={bodyid: xxxxxxxxxxxxxxxxxxxxxx} where xxxxxxxxxxxx is the bodyid now returns the html body. Request still works as expected.

Am running this as a local mod at the moment but would be appreciated if this could be included in a future API upgrade.

Regards
Phil