Skip to content

Commit

Permalink
Use new value component functions in amphp/http 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jul 12, 2019
1 parent 5532eef commit c6b1eac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": ">=7.1",
"amphp/amp": "^2",
"amphp/byte-stream": "^1.6",
"amphp/http": "^1.2",
"amphp/http": "^1.3",
"amphp/socket": "dev-master as 1.0",
"amphp/file": "^0.2 || ^0.3",
"kelunik/certificate": "^1.1",
Expand Down
20 changes: 6 additions & 14 deletions src/Connection/Http1Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Amp\CancelledException;
use Amp\Deferred;
use Amp\Emitter;
use Amp\Http;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Internal\CombinedCancellationToken;
use Amp\Http\Client\Internal\RequestWriter;
Expand Down Expand Up @@ -394,21 +395,12 @@ private function determineKeepAliveTimeout(Response $response): int
return 0;
}

$responseKeepAliveHeader = $response->getHeader('keep-alive');
$params = Http\createFieldValueComponentMap(Http\parseFieldValueComponents($response, 'keep-alive'));

if ($responseKeepAliveHeader === null) {
return $this->priorTimeout;
}

$parts = \array_map('trim', \explode(',', $responseKeepAliveHeader));

$params = [];
foreach ($parts as $part) {
[$key, $value] = \array_map('trim', \explode('=', $part)) + [null, null];
$params[$key] = (int) $value;
}

return $this->priorTimeout = \min(\max(0, $params['timeout'] ?? 0), self::MAX_KEEP_ALIVE_TIMEOUT);
return $this->priorTimeout = \min(
\max(0, $params['timeout'] ?? $this->priorTimeout),
self::MAX_KEEP_ALIVE_TIMEOUT
);
}

private function determineProtocolVersion(Request $request): string
Expand Down

0 comments on commit c6b1eac

Please sign in to comment.