-
Notifications
You must be signed in to change notification settings - Fork 708
/
jsonResult.php
117 lines (101 loc) · 4.05 KB
/
jsonResult.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
// Copyright 2020 Catchpoint Systems Inc.
// Use of this source code is governed by the Polyform Shield 1.0.0 license that can be
// found in the LICENSE.md file.
// Do a really quick check for a pending test to significantly reduce overhead
if (isset($_REQUEST['noposition']) &&
$_REQUEST['noposition'] &&
isset($_REQUEST['test']) &&
strpos($_REQUEST['test'], '_') == 6) {
$base = __DIR__ . '/results';
$parts = explode('_', $_REQUEST['test']);
$dir = $parts[1];
if( count($parts) > 2 && strlen($parts[2]))
$dir .= '/' . $parts[2];
$y = substr($parts[0], 0, 2);
$m = substr($parts[0], 2, 2);
$d = substr($parts[0], 4, 2);
$pendingFile = "$base/$y/$m/$d/$dir/test.waiting";
if (is_file($pendingFile)) {
header("Content-type: application/json; charset=utf-8");
header("Cache-Control: no-cache, must-revalidate", true);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
if( array_key_exists('callback', $_REQUEST) && strlen($_REQUEST['callback']) )
echo "{$_REQUEST['callback']}(";
echo "{\"statusCode\":101,\"statusText\":\"Test pending\",\"id\":\"{$_REQUEST['test']}\"";
if (isset($_REQUEST['r']))
echo ",\"requestId\":\"{$_REQUEST['r']}\"";
echo "}";
if( isset($_REQUEST['callback']) && strlen($_REQUEST['callback']) )
echo ");";
exit;
}
}
require_once('common.inc');
require_once('page_data.inc');
require_once('testStatus.inc');
require_once('video/visualProgress.inc.php');
require_once('breakdown.inc');
require_once('devtools.inc.php');
require_once('archive.inc');
require_once __DIR__ . '/include/JsonResultGenerator.php';
require_once __DIR__ . '/include/TestInfo.php';
require_once __DIR__ . '/include/TestResults.php';
if (isset($test['test']['batch']) && $test['test']['batch']) {
$_REQUEST['f'] = 'json';
include 'resultBatch.inc';
} else {
$ret = array('data' => GetTestStatus($id));
$ret['statusCode'] = $ret['data']['statusCode'];
$ret['statusText'] = $ret['data']['statusText'];
if ($ret['statusCode'] == 200) {
$protocol = getUrlProtocol();
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$urlStart = "$protocol://$host$uri";
$testInfo = TestInfo::fromValues($id, $testPath, $test);
$testResults = TestResults::fromFiles($testInfo);
$infoFlags = getRequestInfoFlags();
$jsonResultGenerator = new JsonResultGenerator($testInfo, $urlStart, new FileHandler(), $infoFlags, FRIENDLY_URLS);
if (!empty($_REQUEST["multistepFormat"])) {
$jsonResultGenerator->forceMultistepFormat(true);
}
if (defined("VER_WEBPAGETEST")) {
$ret["webPagetestVersion"] = VER_WEBPAGETEST;
}
$type = $testInfo->getTestType();
if ($type === 'lighthouse') {
$json_file = "./$testPath/lighthouse.json";
$ret['data'] = array('html_result_url' => "$urlStart/results.php?test=$id");
if (gz_is_file($json_file))
$ret['data']['lighthouse'] = json_decode(gz_file_get_contents($json_file), true);
} else {
$ret['data'] = $jsonResultGenerator->resultDataArray($testResults, $median_metric);
}
ArchiveApi($id);
}
json_response($ret);
}
function getRequestInfoFlags() {
$getFlags = array(
"average" => JsonResultGenerator::WITHOUT_AVERAGE,
"standard" => JsonResultGenerator::WITHOUT_STDDEV,
"median" => JsonResultGenerator::WITHOUT_MEDIAN,
"runs" => JsonResultGenerator::WITHOUT_RUNS,
"requests" => JsonResultGenerator::WITHOUT_REQUESTS,
"console" => JsonResultGenerator::WITHOUT_CONSOLE,
"lighthouse" => JsonResultGenerator::WITHOUT_LIGHTHOUSE,
"rv" => JsonResultGenerator::WITHOUT_REPEAT_VIEW
);
$infoFlags = array();
foreach ($getFlags as $key => $flag) {
if (isset($_GET[$key]) && $_GET[$key] == 0) {
$infoFlags[] = $flag;
}
}
if (!empty($_REQUEST["basic"])) {
$infoFlags[] = JsonResultGenerator::BASIC_INFO_ONLY;
}
return $infoFlags;
}
?>