Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpeedtestController
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 getRandomPackage
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
 postRandomPackage
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/** @noinspection PhpUnhandledExceptionInspection */
3declare(strict_types=1);
4
5// TODO unit tests !
6
7use Slim\Http\Response;
8use Slim\Http\ServerRequest as Request;
9
10class SpeedtestController extends Controller {
11  public static function getRandomPackage(Request $request, Response $response): Response {
12    $size = (int) $request->getAttribute('size');
13
14    apache_setenv('no-gzip', '1');
15
16    if (($size > 8388608 * 8) or ($size < 16)) {
17      throw new HttpError("Unsupported test size ($size)", 406);
18    }
19
20    $package = str_repeat('a', $size - 1);
21    $package .= '=';
22
23    $response->getBody()->write($package);
24    return $response
25      ->withHeader('Content-Transfer-Encoding', 'binary')
26      ->withHeader('Content-Type', 'text/plain');
27  }
28
29  public static function postRandomPackage(/** @noinspection PhpUnusedParameterInspection */ Request $request, Response $response): Response {
30    return $response->withJson([
31      'requestTime' => $_SERVER['REQUEST_TIME_FLOAT'],
32      'packageReceivedSize' => $_SERVER['CONTENT_LENGTH']
33    ]);
34  }
35}