Skip to content

Commit 4503cc6

Browse files
committed
added response body
1 parent 90aa145 commit 4503cc6

10 files changed

Lines changed: 94 additions & 3 deletions

File tree

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ $ webpagetest --help
5353
* **testinfo** _\<id\>_: get test request info/details
5454
* **history** _[days]_: get history of previously run tests
5555
* **googlecsi** _[options] \<id\>_: get Google CSI data (Client Side Instrumentation)
56+
* **response** _[options] \<id\>_: get response body for text resources
5657
* **waterfall** _[options] \<id\>_: get the waterfall PNG image
5758
* **screenshot** _[options] \<id\>_: get the fully loaded page screenshot in JPG format (PNG if in full resolution)
5859
* **video** _[options] \<tests\>_: create a video from _\<tests\>_ (comma separated test ids)
@@ -135,7 +136,7 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
135136
* **-S, --specs** _\<json_or_file\>_: set the specs for performance test suite
136137
* **-r, --reporter** _\<name\>_: set performance test suite reporter output: [dot]|spec|tap|xunit|list|progress|min|nyan|landing|json|doc|markdown|teamcity
137138

138-
#### Run (works for **pagespeed**, **utilization**, **request**, **timeline**, **netlog**, **console**, **googlecsi**, **waterfall** and **screenshot** commands)
139+
#### Run (works for **pagespeed**, **utilization**, **request**, **timeline**, **netlog**, **console**, **googlecsi**, **response**, **waterfall** and **screenshot** commands)
139140
* **-r, --run** _\<number\>_: which run number on a multiple runs test [1]
140141
* **-c, --cached**: get the Repeat View (cached view) instead of default First View (primed cache)
141142

@@ -162,6 +163,9 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
162163
#### Video (works for **video** command only)
163164
* **-e, --end** _\<end_point\>_: frame comparison end point: [visual]=visually complete | all=last change | doc=document complete | full=fully loaded
164165

166+
#### Response (works for **response** command only)
167+
* **-R, --request** _\<number\>_: the request number [1]
168+
165169
### Examples
166170
#### 1. Get available locations
167171
```bash
@@ -326,6 +330,7 @@ Methods and options (including the one letter shorthands) are the same when usin
326330
* `getTestInfo(id, options, callback)`
327331
* `getHistory(days, options, callback)`
328332
* `getGoogleCsiData(id, options, callback)`
333+
* `getResponseBody(id, options, callback)`
329334
* `getWaterfallImage(id, options, callback)`
330335
* `getScreenshotImage(id, options, callback)`
331336
* `createVideo(tests, options, callback)`
@@ -440,7 +445,7 @@ wpt.runTest(script, function(err, data) {
440445
* **specs**: _String_, set the specs for performance test suite
441446
* **reporter**: _String_, set performance test suite reporter output: [dot]|spec|tap|xunit|list|progress|min|nyan|landing|json|doc|markdown|teamcity
442447

443-
#### Run (works for `getPageSpeedData`, `getUtilizationData`, `getRequestData`, `getTimelineData`, `getNetLogData`, `getConsoleLogData`, `getGoogleCsiData`, `getWaterfallImage` and `getScreenshotImage` methods)
448+
#### Run (works for `getPageSpeedData`, `getUtilizationData`, `getRequestData`, `getTimelineData`, `getNetLogData`, `getConsoleLogData`, `getGoogleCsiData`, `getResponseBody`, `getWaterfallImage` and `getScreenshotImage` methods)
444449
* **run**: _Number_, the test run number for multiple runs tests (default: 1, first test)
445450
* **repeatView**: _Boolean_, if `true` returns the repeat view (cached) data
446451

@@ -467,6 +472,9 @@ wpt.runTest(script, function(err, data) {
467472
#### Video (works for `createVideo` method only)
468473
* **comparisonEndPoint** _String_: frame comparison end point: [visual]=visually complete | all=last change | doc=document complete | full=fully loaded
469474

475+
#### Response (works for `getResponseBody` method only)
476+
* **request** _Number_: the request number [1]
477+
470478
### Examples
471479

472480
#### 1. Instantiating
@@ -625,6 +633,7 @@ $ npm test
625633

626634
## Changelog
627635

636+
* 0.2.2: Added response body command/method
628637
* 0.2.1: Added history, video, player, googleCsi commands and continuous option
629638
* 0.2.0: Replaced jsonml by xml2js dependency
630639
* 0.1.3: Test results extra data (breakdown, domains, requests, pagespeed)

lib/mapping.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,15 @@ var options = {
556556
info: 'frame comparison end point: [visual]=visually complete | all=last change | doc=document complete | full=fully loaded',
557557
valid: /^(?:visual|all|doc|full)$/
558558
}
559+
},
560+
'response': {
561+
'request': {
562+
name: 'request',
563+
api: 'request',
564+
key: 'R',
565+
param: 'number',
566+
info: 'the request number [1]'
567+
}
559568
}
560569
};
561570

@@ -653,6 +662,12 @@ var commands = {
653662
options: [options.run],
654663
info: 'get Google CSI data (Client Side Instrumentation)'
655664
},
665+
'response': {
666+
name: 'getResponseBody',
667+
param: 'id',
668+
options: [options.run, options.response],
669+
info: 'get response body for text resources'
670+
},
656671
'waterfall': {
657672
name: 'getWaterfallImage',
658673
param: 'id',

lib/webpagetest.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ var paths = {
3333
history: 'testlog.php',
3434
videoCreation: 'video/create.php',
3535
videoView: 'video/view.php',
36-
googleCsi: 'google/google_csi.php'
36+
googleCsi: 'google/google_csi.php',
37+
responseBody: 'response_body.php'
3738
};
3839

3940
var filenames = {
@@ -184,6 +185,8 @@ function api(pathname, callback, query, options) {
184185
asyncParserCallback.bind(callback, options));
185186
} else if (info.type === 'text/html') {
186187
data = {result: (reHTMLOutput.exec(data) || [])[1]};
188+
} else if (info.type === 'text/plain') {
189+
data = {result: data.toString()};
187190
}
188191
}
189192
} catch (ex) {
@@ -565,6 +568,20 @@ function getGoogleCsiData(id, options, callback) {
565568
return api.call(this, paths.googleCsi, callback, query, options);
566569
}
567570

571+
function getResponseBody(id, options, callback) {
572+
var query;
573+
574+
callback = callback || options;
575+
options = options === callback ? {} : options;
576+
options.args = options.args || {
577+
type: 'text/plain'
578+
};
579+
query = setFilename({test: id}, options);
580+
query.request = options.request || 1;
581+
582+
return api.call(this, paths.responseBody, callback, query, options);
583+
}
584+
568585
function getWaterfallImage(id, options, callback) {
569586
var query,
570587
pathname = paths.waterfall;
@@ -707,6 +724,7 @@ WebPageTest.prototype = {
707724
getWaterfallImage: getWaterfallImage,
708725
getScreenshotImage: getScreenshotImage,
709726
getGoogleCsiData: getGoogleCsiData,
727+
getResponseBody: getResponseBody,
710728
getEmbedVideoPlayer: getEmbedVideoPlayer,
711729
createVideo: createVideo,
712730
scriptToString: WebPageTest.scriptToString,
@@ -729,6 +747,7 @@ WebPageTest.prototype = {
729747
testinfo: getTestInfo,
730748
history: getHistory,
731749
googlecsi: getGoogleCsiData,
750+
response: getResponseBody,
732751
player: getEmbedVideoPlayer,
733752
video: createVideo,
734753
waterfall: getWaterfallImage,

test/dryrun-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,26 @@ describe('Dry Run', function() {
409409
});
410410
});
411411

412+
it('get response body for first run first request', function(done) {
413+
wpt.getResponseBody('140101_AB_12', {dryRun: true}, function(err, data) {
414+
if (err) throw err;
415+
assert.equal(data.url, wptServer + 'response_body.php?test=140101_AB_12&run=1&cached=0&request=1');
416+
done();
417+
});
418+
});
419+
420+
it('get response body for cached 3rd run 5th request', function(done) {
421+
wpt.getResponseBody('140101_AB_12', {
422+
dryRun: true,
423+
repeatView: true,
424+
run: 3,
425+
request: 5
426+
}, function(err, data) {
427+
if (err) throw err;
428+
assert.equal(data.url, wptServer + 'response_body.php?test=140101_AB_12&run=3&cached=1&request=5');
429+
done();
430+
});
431+
});
432+
412433
});
413434
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Usage: response [options] <id>
3+
4+
Options:
5+
6+
-h, --help output usage information
7+
-r, --run <number> which run number on a multiple runs test [1]
8+
-c, --cached get the Repeat View (cached view) instead of default First View (primed cache)
9+
-R, --request <number> the request number [1]
10+

test/fixtures/command-line/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
testinfo <id> get test request info/details
2020
history [days] get history of previously run tests
2121
googlecsi [options] <id> get Google CSI data (Client Side Instrumentation)
22+
response [options] <id> get response body for text resources
2223
waterfall [options] <id> get the waterfall PNG image
2324
screenshot [options] <id> get the fully loaded page screenshot in JPG format (PNG if in full resolution)
2425
video [options] <tests> create a video from <tests> (comma separated test ids)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "text/plain",
3+
"data": {
4+
"result": "foobar"
5+
}
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foobar

test/helpers/nock-server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var reqResMap = {
3838
'/video/view.php?embed=1&id=130416_36ed6e37013655a14b2b857cdccec99db72adcaa': 'embeddedVideoPlayer.html',
3939
'/google/google_csi.php?test=140101_AB_12': 'googleCsiData.csv',
4040
'/google/google_csi.php?test=140101_AB_12&run=2': 'googleCsiDataRun2.csv',
41+
'/response_body.php?test=140101_AB_12&run=1&cached=0&request=1': 'response.txt',
4142

4243
// test results for multi runs with/without custom median metric
4344
'/xmlResult.php?test=130619_KK_6A2': 'testResultsMultiRunsDefaultMedianMetric.xml',

test/nock-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ describe('Example WebPageTest', function() {
287287
});
288288
});
289289

290+
it('gets response body', function(done) {
291+
wpt.getResponseBody('140101_AB_12', function(err, data) {
292+
if (err) throw err;
293+
assert.deepEqual(data.result.trim(), ResponseObjects.response.data.result);
294+
done();
295+
});
296+
});
297+
290298
// not found / invalid
291299

292300
it('gets an invalid test status request then returns a not found test status object', function(done) {

0 commit comments

Comments
 (0)