diff --git a/CHANGELOG.md b/CHANGELOG.md index 426993f..02cc2a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 3.6.0 - 2023-02-11 + +### Added + +- `Innmind\OperatingSystem\Config::limitHttpConcurrencyTo()` + +### Changed + +- Requires `innmind/http-transport:~6.4` + ## 3.5.0 - 2023-01-29 ### Added diff --git a/composer.json b/composer.json index e002f0a..d3efe34 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "innmind/server-control": "~5.0", "innmind/filesystem": "~6.2", "innmind/socket": "~6.0", - "innmind/http-transport": "~6.3", + "innmind/http-transport": "~6.4", "innmind/time-warp": "~3.0", "innmind/signals": "~3.0", "innmind/file-watch": "~3.1", diff --git a/src/Config.php b/src/Config.php index 0bae116..e17d16a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -9,29 +9,41 @@ Capabilities, Streams, }; +use Innmind\Immutable\Maybe; final class Config { private CaseSensitivity $caseSensitivity; private Capabilities $streamCapabilities; private EnvironmentPath $path; + /** @var Maybe */ + private Maybe $maxHttpConcurrency; + /** + * @param Maybe $maxHttpConcurrency + */ private function __construct( CaseSensitivity $caseSensitivity, Capabilities $streamCapabilities, EnvironmentPath $path, + Maybe $maxHttpConcurrency, ) { $this->caseSensitivity = $caseSensitivity; $this->streamCapabilities = $streamCapabilities; $this->path = $path; + $this->maxHttpConcurrency = $maxHttpConcurrency; } public static function of(): self { + /** @var Maybe */ + $maxHttpConcurrency = Maybe::nothing(); + return new self( CaseSensitivity::sensitive, Streams::fromAmbientAuthority(), EnvironmentPath::of(\getenv('PATH') ?: ''), + $maxHttpConcurrency, ); } @@ -44,6 +56,7 @@ public function caseInsensitiveFilesystem(): self CaseSensitivity::insensitive, $this->streamCapabilities, $this->path, + $this->maxHttpConcurrency, ); } @@ -56,6 +69,7 @@ public function useStreamCapabilities(Capabilities $capabilities): self $this->caseSensitivity, $capabilities, $this->path, + $this->maxHttpConcurrency, ); } @@ -68,6 +82,20 @@ public function withEnvironmentPath(EnvironmentPath $path): self $this->caseSensitivity, $this->streamCapabilities, $path, + $this->maxHttpConcurrency, + ); + } + + /** + * @param positive-int $max + */ + public function limitHttpConcurrencyTo(int $max): self + { + return new self( + $this->caseSensitivity, + $this->streamCapabilities, + $this->path, + Maybe::just($max), ); } @@ -94,4 +122,14 @@ public function environmentPath(): EnvironmentPath { return $this->path; } + + /** + * @internal + * + * @return Maybe + */ + public function maxHttpConcurrency(): Maybe + { + return $this->maxHttpConcurrency; + } } diff --git a/src/Remote/Generic.php b/src/Remote/Generic.php index 7e7b7dc..82d0dc9 100644 --- a/src/Remote/Generic.php +++ b/src/Remote/Generic.php @@ -75,11 +75,20 @@ public function socket(Transport $transport, Authority $authority): Maybe public function http(): HttpTransport { - return $this->http ??= Curl::of( + if ($this->http) { + return $this->http; + } + + $http = Curl::of( $this->clock, new Chunk, $this->config->streamCapabilities(), ); + + return $this->http = $this->config->maxHttpConcurrency()->match( + static fn($max) => $http->maxConcurrency($max), + static fn() => $http, + ); } public function sql(Url $server): Connection