From d6629068578589bbc8c2e5d9e11a57c03fcf09d3 Mon Sep 17 00:00:00 2001 From: Fabiana Romagnoli Date: Fri, 26 Apr 2024 16:47:53 +0200 Subject: [PATCH] Make maxBodySize nullable Symfony was updated to 4 to be able to use default env var processor, that was introduced in Symfony 4.3. --- .env.dist | 1 - composer.json | 6 +++--- docker-compose.yml | 2 +- esb.yml.sample | 19 ++++++++++--------- services.yml | 8 +++++--- services_test.yml | 2 +- src/Service/HttpProducersServer.php | 11 +++++++---- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.env.dist b/.env.dist index f52c69d..8930ded 100644 --- a/.env.dist +++ b/.env.dist @@ -5,7 +5,6 @@ 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 diff --git a/composer.json b/composer.json index bb416f9..7e7334e 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "php": "~7.4.0|~8.0.0", "ext-pcntl": "*", "ext-json": "*", - "symfony/dependency-injection": "^3.3", - "symfony/config": "^3.3", - "symfony/yaml": "^3.3", + "symfony/dependency-injection": "^4.3", + "symfony/config": "^4.3", + "symfony/yaml": "^4.3", "amphp/beanstalk": "^0.3.2", "monolog/monolog": "^1.23", "dragonmantank/cron-expression": "^2.0", diff --git a/docker-compose.yml b/docker-compose.yml index 5c58db8..999865d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,7 +29,7 @@ services: - "${MAILHOG_WEB_PORT_HOST}:8025" elasticsearch: - image: "docker.elastic.co/elasticsearch/elasticsearch-oss:7.4.0" + image: "docker.elastic.co/elasticsearch/elasticsearch-oss:7.8.0" env_file: - .env environment: diff --git a/esb.yml.sample b/esb.yml.sample index 2833b2d..efeca74 100644 --- a/esb.yml.sample +++ b/esb.yml.sample @@ -1,13 +1,14 @@ parameters: - beanstalkd: tcp://127.0.0.1:11300 # Beanstalkd connection URI - http_server_port: 34981 # HTTP Server Port - logger_mail_to: toemail@address.com # Email address where to send significant events mail notifications - logger_mail_from: "From Name " # From name/address for significant events mail notifications - console_port: 8080 # Web console port - console_username: admin # Web console username - console_password: password # Web console password - console_log_file: /tmp/esb_console.log # Web console server log file - elasticsearch_base_uri: '%env(string:ES_BASE_URI)%' # ElasticSearch base URI (i.e. http://elasticsearch:9200) + beanstalkd: tcp://127.0.0.1:11300 # Beanstalkd connection URI + http_server_port: 34981 # HTTP Server Port + http_server_max_body_size: '%env(default::int:ESB_HTTP_SERVER_MAX_BODY_SIZE)%' # HTTP Server max body size + logger_mail_to: toemail@address.com # Email address where to send significant events mail notifications + logger_mail_from: "From Name " # From name/address for significant events mail notifications + console_port: 8080 # Web console port + console_username: admin # Web console username + console_password: password # Web console password + console_log_file: /tmp/esb_console.log # Web console server log file + elasticsearch_base_uri: '%env(string:ES_BASE_URI)%' # ElasticSearch base URI (i.e. http://elasticsearch:9200) services: _defaults: diff --git a/services.yml b/services.yml index 39d8b97..50847e1 100644 --- a/services.yml +++ b/services.yml @@ -20,17 +20,17 @@ services: Monolog\Handler\StreamHandler: class: \Monolog\Handler\StreamHandler - arguments: [ 'php://stdout', !php/const:Monolog\Logger::DEBUG ] + arguments: [ 'php://stdout', !php/const Monolog\Logger::DEBUG ] Monolog\Handler\ErrorLogHandler: class: \Monolog\Handler\ErrorLogHandler - arguments: [ !php/const:Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, !php/const:Monolog\Logger::ERROR ] + arguments: [ !php/const Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, !php/const Monolog\Logger::ERROR ] Monolog\Formatter\HtmlFormatter: {} Monolog\Handler\NativeMailerHandler: class: \Monolog\Handler\NativeMailerHandler - arguments: [ '%logger_mail_to%', 'Significant event from ESB', '%logger_mail_from%', !php/const:Monolog\Logger::WARNING ] + arguments: [ '%logger_mail_to%', 'Significant event from ESB', '%logger_mail_from%', !php/const Monolog\Logger::WARNING ] calls: - method: setFormatter arguments: @@ -76,6 +76,7 @@ services: $classMetadataFactory: '@serializer.class_metadata_factory' $propertyTypeExtractor: '@serializer.object_normalizer.reflection_extractor' serializer: + public: true class: \Symfony\Component\Serializer\Serializer arguments: - ['@serializer.array_denormalizer', '@serializer.date_time_normalizer', '@serializer.object_normalizer'] @@ -85,5 +86,6 @@ services: Symfony\Component\Serializer\Normalizer\DenormalizerInterface: '@serializer' Webgriffe\Esb\Service\ElasticSearch: + public: true arguments: $normalizer: '@serializer' diff --git a/services_test.yml b/services_test.yml index adbc1a9..8217e45 100644 --- a/services_test.yml +++ b/services_test.yml @@ -1,7 +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)%' + http_server_max_body_size: '%env(default::int:ESB_HTTP_SERVER_MAX_BODY_SIZE)%' logger_mail_to: "toemail@address.com" logger_mail_from: "From Name " console_port: '%env(int:ESB_CONSOLE_PORT)%' diff --git a/src/Service/HttpProducersServer.php b/src/Service/HttpProducersServer.php index 711d191..36131ef 100644 --- a/src/Service/HttpProducersServer.php +++ b/src/Service/HttpProducersServer.php @@ -44,11 +44,11 @@ class HttpProducersServer private $httpServer; /** - * @var int + * @var int|null */ private $maxBodySize; - public function __construct(int $port, LoggerInterface $logger, int $maxBodySize) + public function __construct(int $port, LoggerInterface $logger, ?int $maxBodySize) { $this->port = $port; $this->logger = $logger; @@ -66,8 +66,11 @@ public function start(): Promise Socket\listen("[::]:{$this->port}"), ]; - $options = new Options(); - $options->withBodySizeLimit($this->maxBodySize); + $options = null; + if ($this->maxBodySize !== null) { + $options = new Options(); + $options->withBodySizeLimit($this->maxBodySize); + } $this->httpServer = new HttpServer( $sockets,