Skip to content

Commit

Permalink
Add ability to change the size of the buffer to send the content of t…
Browse files Browse the repository at this point in the history
…he message body (#80)
  • Loading branch information
vjik authored Jul 12, 2024
1 parent 5bde0a8 commit 18658da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 3.0.0 under development

- New #80: Add ability to change the size of the buffer to send the content of the message body (@vjik)
- Chg #76: Allow to use any PSR logger, `NullLogger` by default (@vjik)
- Chg #77: Remove `ServerRequestFactory` (@vjik)
- Chg #77: Mark `SapiEmitter` as internal (@vjik)
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ recursive merge parameters.
`$nestedEventsGroups` — configuration group names that are included into events' configuration group. This is needed for
reverse and recursive merge events' configurations.

`$configModifiers`[configuration modifiers](https://github.com/yiisoft/config#configuration-modifiers).

`$configDirectory` — the relative path from `$rootPath` to the configuration storage location.

`$vendorDirectory` — the relative path from `$rootPath` to the vendor directory.

`$configMergePlanFile` — the relative path from `$configDirectory` to merge plan.

`$logger` — the logger to collect errors while container is building.

`$bufferSize` — the size of the buffer in bytes to send the content of the message body (default, 8Mb).

#### Immutable setters

If the configuration instance settings differ from the default you can specify a customized configuration instance:
Expand Down
11 changes: 8 additions & 3 deletions src/HttpApplicationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ final class HttpApplicationRunner extends ApplicationRunner
* @param string $configDirectory The relative path from {@see $rootPath} to the configuration storage location.
* @param string $vendorDirectory The relative path from {@see $rootPath} to the vendor directory.
* @param string $configMergePlanFile The relative path from {@see $configDirectory} to merge plan.
* @param LoggerInterface|null $logger The logger to collect errors while container is building.
* @param int|null $bufferSize The size of the buffer in bytes to send the content of the message body.
*
* @psalm-param list<string> $nestedParamsGroups
* @psalm-param list<string> $nestedEventsGroups
Expand All @@ -78,6 +80,7 @@ public function __construct(
string $vendorDirectory = 'vendor',
string $configMergePlanFile = '.merge-plan.php',
private ?LoggerInterface $logger = null,
private ?int $bufferSize = null,
) {
parent::__construct(
$rootPath,
Expand Down Expand Up @@ -131,8 +134,10 @@ public function run(): void

$container = $this->getContainer();

// Register error handler with real container-configured dependencies.
/** @var ErrorHandler $actualErrorHandler */
/**
* Register error handler with real container-configured dependencies.
* @var ErrorHandler $actualErrorHandler
*/
$actualErrorHandler = $container->get(ErrorHandler::class);
$this->registerErrorHandler($actualErrorHandler, $temporaryErrorHandler);

Expand Down Expand Up @@ -186,7 +191,7 @@ private function createTemporaryErrorHandler(): ErrorHandler
*/
private function emit(ServerRequestInterface $request, ResponseInterface $response): void
{
(new SapiEmitter())->emit($response, $request->getMethod() === Method::HEAD);
(new SapiEmitter($this->bufferSize))->emit($response, $request->getMethod() === Method::HEAD);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/SapiEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class SapiEmitter
/**
* @param int|null $bufferSize The size of the buffer in bytes to send the content of the message body.
*/
public function __construct(int $bufferSize = null)
public function __construct(?int $bufferSize = null)
{
if ($bufferSize !== null && $bufferSize < 1) {
throw new InvalidArgumentException('Buffer size must be greater than zero.');
Expand Down

0 comments on commit 18658da

Please sign in to comment.