Skip to content

Commit

Permalink
Make body size limit configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianaromagnoli committed Apr 26, 2024
1 parent 1d78cda commit c85c588
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ESB_BEANSTALKD_URL=tcp://beanstalkd:11300
ESB_CONSOLE_PORT=8080
# ESB_HTTP_SERVER is the port for the ESB's HTTP request producers
ESB_HTTP_SERVER_PORT=34981
#ESB_HTTP_SERVER_MAX_BODY_SIZE is an optional parameter. You shoud set it if you need a value larger then default, that is 10485760
ESB_HTTP_SERVER_MAX_BODY_SIZE=10485760

# MAILHOG_WEB_PORT_HOST is the host's port binding of the MailHog 8025 web UI server port
MAILHOG_WEB_PORT_HOST=8025
Expand Down
2 changes: 2 additions & 0 deletions services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ services:
Webgriffe\Esb\Service\HttpProducersServer:
arguments:
$port: '%http_server_port%'
$logger: '@Psr\Log\LoggerInterface'
$maxBodySize: '%http_server_max_body_size%'

Monolog\Handler\StreamHandler:
class: \Monolog\Handler\StreamHandler
Expand Down
1 change: 1 addition & 0 deletions services_test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
beanstalkd: '%env(string:ESB_BEANSTALKD_URL)%'
http_server_port: '%env(int:ESB_HTTP_SERVER_PORT)%'
http_server_max_body_size: '%env(ESB_HTTP_SERVER_MAX_BODY_SIZE)%'
logger_mail_to: "[email protected]"
logger_mail_from: "From Name <[email protected]>"
console_port: '%env(int:ESB_CONSOLE_PORT)%'
Expand Down
15 changes: 13 additions & 2 deletions src/Service/HttpProducersServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use function Amp\call;
use Amp\CallableMaker;
use Amp\Http\Server\HttpServer;
use Amp\Http\Server\Options;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Response;
Expand Down Expand Up @@ -42,10 +43,16 @@ class HttpProducersServer
*/
private $httpServer;

public function __construct(int $port, LoggerInterface $logger)
/**
* @var int
*/
private $maxBodySize;

public function __construct(int $port, LoggerInterface $logger, int $maxBodySize)
{
$this->port = $port;
$this->logger = $logger;
$this->maxBodySize = $maxBodySize;
}

/**
Expand All @@ -59,10 +66,14 @@ public function start(): Promise
Socket\listen("[::]:{$this->port}"),
];

$options = new Options();
$options->withBodySizeLimit($this->maxBodySize);

$this->httpServer = new HttpServer(
$sockets,
new CallableRequestHandler($this->callableFromInstanceMethod('requestHandler')),
new NullLogger()
new NullLogger(),
$options
);

yield $this->httpServer->start();
Expand Down

0 comments on commit c85c588

Please sign in to comment.