-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
234 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Amp\Http\Client\Connection; | ||
|
||
use Amp\CancellationToken; | ||
use Amp\Http\Client\ConnectionInfo; | ||
use Amp\Http\Client\Request; | ||
use Amp\Http\Client\Response; | ||
use Amp\Promise; | ||
|
||
interface Connection | ||
{ | ||
/** | ||
* @param Request $request | ||
* @param CancellationToken|null $token | ||
* | ||
* @return Promise<Response> | ||
*/ | ||
public function request(Request $request, ?CancellationToken $token = null): Promise; | ||
|
||
/** | ||
* @return ConnectionInfo | ||
*/ | ||
public function getConnectionInfo(): ConnectionInfo; | ||
|
||
public function isClosed(): bool; | ||
|
||
public function close(): Promise; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Amp\Http\Client\Connection; | ||
|
||
use Amp\Http\Client\Request; | ||
use Amp\Socket\Socket; | ||
|
||
interface ConnectionPool | ||
{ | ||
/** | ||
* @param Socket $socket | ||
* | ||
* @return Connection | ||
*/ | ||
public function createConnection(Socket $socket): Connection; | ||
|
||
/** | ||
* @param Request $request | ||
* | ||
* @return Connection|null | ||
*/ | ||
public function getConnection(Request $request): ?Connection; | ||
|
||
/** | ||
* @return string[] A list of supported application-layer protocols (ALPNs). | ||
*/ | ||
public function getApplicationLayerProtocols(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Amp\Http\Client\Connection; | ||
|
||
use Amp\Http\Client\Request; | ||
use Amp\Socket\Socket; | ||
|
||
final class DefaultConnectionPool implements ConnectionPool | ||
{ | ||
private $connections = []; | ||
|
||
public function createConnection(Socket $socket): Connection | ||
{ | ||
$connection = new Http1Connection($socket); | ||
$this->connections[$socket->getRemoteAddress()->toString()] = $connection; | ||
return $connection; | ||
} | ||
|
||
public function getConnection(Request $request): ?Connection | ||
{ | ||
$uri = $request->getUri(); | ||
|
||
$address = $uri->getHost(); | ||
$port = $uri->getPort(); | ||
|
||
if ($port !== null) { | ||
$address .= ':' . $port; | ||
} | ||
|
||
if (isset($this->connections[$address])) { | ||
return $this->connections[$address]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function getApplicationLayerProtocols(): array | ||
{ | ||
return ['http/1.1']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.