|
39 | 39 |
|
40 | 40 | $http = new Server("0.0.0.0", App::getEnv('PORT', 80));
|
41 | 41 | $payloadSize = 6 * (1024 * 1024); // 6MB
|
| 42 | +$workerNumber = swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6)); |
| 43 | + |
| 44 | +$http |
| 45 | + ->set([ |
| 46 | + 'worker_num' => $workerNumber, |
| 47 | + 'open_http2_protocol' => true, |
| 48 | + // 'document_root' => __DIR__.'/../public', |
| 49 | + // 'enable_static_handler' => true, |
| 50 | + 'http_compression' => true, |
| 51 | + 'http_compression_level' => 6, |
| 52 | + 'package_max_length' => $payloadSize, |
| 53 | + 'buffer_output_size' => $payloadSize, |
| 54 | + ]); |
42 | 55 |
|
43 | 56 | // Mock Routes
|
44 | 57 | App::get('/v1/mock/tests/foo')
|
|
236 | 249 | ->label('sdk.mock', true)
|
237 | 250 | ->inject('request')
|
238 | 251 | ->inject('response')
|
239 |
| - ->action(function (Request $request, Response $response) { |
| 252 | + ->action(function (Request $request, UtopiaSwooleResponse $response) { |
240 | 253 | $res = [
|
241 | 254 | 'x-sdk-name' => $request->getHeader('x-sdk-name'),
|
242 | 255 | 'x-sdk-platform' => $request->getHeader('x-sdk-platform'),
|
|
248 | 261 | }, array_keys($res), $res);
|
249 | 262 | $res = implode("; ", $res);
|
250 | 263 |
|
251 |
| - $response->dynamic(new Document(['result' => $res]), Response::MODEL_MOCK); |
| 264 | + $response->json(['result' => $res]); |
252 | 265 | });
|
253 | 266 |
|
254 | 267 | App::get('/v1/mock/tests/general/download')
|
|
264 | 277 | ->label('sdk.response.code', Response::STATUS_CODE_OK)
|
265 | 278 | ->label('sdk.mock', true)
|
266 | 279 | ->inject('response')
|
267 |
| - ->action(function (Response $response) { |
| 280 | + ->action(function (UtopiaSwooleResponse $response) { |
268 | 281 |
|
269 | 282 | $response
|
270 | 283 | ->setContentType('text/plain')
|
|
293 | 306 | ->param('file', [], new File(), 'Sample file param', skipValidation: true)
|
294 | 307 | ->inject('request')
|
295 | 308 | ->inject('response')
|
296 |
| - ->action(function (string $x, int $y, array $z, mixed $file, Request $request, Response $response) { |
| 309 | + ->action(function (string $x, int $y, array $z, mixed $file, Request $request, UtopiaSwooleResponse $response) { |
297 | 310 |
|
298 | 311 | $file = $request->getFiles('file');
|
299 | 312 |
|
|
375 | 388 | ->label('sdk.response.model', Response::MODEL_MOCK)
|
376 | 389 | ->label('sdk.mock', true)
|
377 | 390 | ->inject('response')
|
378 |
| - ->action(function (Response $response) { |
| 391 | + ->action(function (UtopiaSwooleResponse $response) { |
379 | 392 |
|
380 | 393 | $response->redirect('/v1/mock/tests/general/redirect/done');
|
381 | 394 | });
|
|
409 | 422 | ->label('sdk.mock', true)
|
410 | 423 | ->inject('response')
|
411 | 424 | ->inject('request')
|
412 |
| - ->action(function (Response $response, Request $request) { |
| 425 | + ->action(function (UtopiaSwooleResponse $response, Request $request) { |
413 | 426 |
|
414 | 427 | $response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', $request->getHostname(), true, true);
|
415 | 428 | });
|
|
446 | 459 | ->label('sdk.response.model', Response::MODEL_NONE)
|
447 | 460 | ->label('sdk.mock', true)
|
448 | 461 | ->inject('response')
|
449 |
| - ->action(function (Response $response) { |
| 462 | + ->action(function (UtopiaSwooleResponse $response) { |
450 | 463 |
|
451 | 464 | $response->noContent();
|
452 | 465 | });
|
|
524 | 537 | ->label('sdk.response.model', Response::MODEL_ANY)
|
525 | 538 | ->label('sdk.mock', true)
|
526 | 539 | ->inject('response')
|
527 |
| - ->action(function (Response $response) { |
| 540 | + ->action(function (UtopiaSwooleResponse $response) { |
528 | 541 |
|
529 | 542 | $response
|
530 | 543 | ->setStatusCode(502)
|
|
542 | 555 | ->param('scope', '', new Text(100), 'OAuth2 scope list.')
|
543 | 556 | ->param('state', '', new Text(1024), 'OAuth2 state.')
|
544 | 557 | ->inject('response')
|
545 |
| - ->action(function (string $client_id, string $redirectURI, string $scope, string $state, Response $response) { |
| 558 | + ->action(function (string $client_id, string $redirectURI, string $scope, string $state, UtopiaSwooleResponse $response) { |
546 | 559 |
|
547 | 560 | $response->redirect($redirectURI . '?' . \http_build_query(['code' => 'abcdef', 'state' => $state]));
|
548 | 561 | });
|
|
560 | 573 | ->param('code', '', new Text(100), 'OAuth2 state.', true)
|
561 | 574 | ->param('refresh_token', '', new Text(100), 'OAuth2 refresh token.', true)
|
562 | 575 | ->inject('response')
|
563 |
| - ->action(function (string $client_id, string $client_secret, string $grantType, string $redirectURI, string $code, string $refreshToken, Response $response) { |
| 576 | + ->action(function (string $client_id, string $client_secret, string $grantType, string $redirectURI, string $code, string $refreshToken, UtopiaSwooleResponse $response) { |
564 | 577 |
|
565 | 578 | if ($client_id != '1') {
|
566 | 579 | throw new Exception(Exception::GENERAL_MOCK, 'Invalid client ID');
|
|
600 | 613 | ->label('docs', false)
|
601 | 614 | ->param('token', '', new Text(100), 'OAuth2 Access Token.')
|
602 | 615 | ->inject('response')
|
603 |
| - ->action(function (string $token, Response $response) { |
| 616 | + ->action(function (string $token, UtopiaSwooleResponse $response) { |
604 | 617 |
|
605 | 618 | if ($token != '123456') {
|
606 | 619 | throw new Exception(Exception::GENERAL_MOCK, 'Invalid token');
|
|
619 | 632 | ->label('scope', 'public')
|
620 | 633 | ->label('docs', false)
|
621 | 634 | ->inject('response')
|
622 |
| - ->action(function (Response $response) { |
| 635 | + ->action(function (UtopiaSwooleResponse $response) { |
623 | 636 |
|
624 | 637 | $response->json([
|
625 | 638 | 'result' => 'success',
|
|
632 | 645 | ->label('scope', 'public')
|
633 | 646 | ->label('docs', false)
|
634 | 647 | ->inject('response')
|
635 |
| - ->action(function (Response $response) { |
| 648 | + ->action(function (UtopiaSwooleResponse $response) { |
636 | 649 |
|
637 | 650 | $response
|
638 | 651 | ->setStatusCode(Response::STATUS_CODE_BAD_REQUEST)
|
|
646 | 659 | ->inject('utopia')
|
647 | 660 | ->inject('response')
|
648 | 661 | ->inject('request')
|
649 |
| - ->action(function (App $utopia, Response $response, Request $request) { |
| 662 | + ->action(function (App $utopia, UtopiaSwooleResponse $response, Request $request) { |
650 | 663 |
|
651 | 664 | $result = [];
|
652 | 665 | $route = $utopia->getRoute();
|
|
665 | 678 | throw new Exception(Exception::GENERAL_MOCK, 'Failed to save results', 500);
|
666 | 679 | }
|
667 | 680 |
|
668 |
| - $response->dynamic(new Document(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']), Response::MODEL_MOCK); |
| 681 | + $response->json(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']); |
669 | 682 | });
|
670 | 683 |
|
671 | 684 | App::error()
|
@@ -714,7 +727,6 @@ function ($utopia, $error, $request, $response) {
|
714 | 727 | break;
|
715 | 728 | default:
|
716 | 729 | $code = 500; // All other errors get the generic 500 server error status code
|
717 |
| - $message = 'Server Error'; |
718 | 730 | }
|
719 | 731 |
|
720 | 732 | $output = ((App::isDevelopment())) ? [
|
|
0 commit comments