diff options
Diffstat (limited to 'src/Request.php')
-rw-r--r-- | src/Request.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/Request.php b/src/Request.php index ceb7dbb..82ce0d3 100644 --- a/src/Request.php +++ b/src/Request.php @@ -8,8 +8,9 @@ class Request protected string $host; protected string $path; protected array $query; + protected ?ClientCertificate $clientCertificate; - public function __construct(string $url) + public function __construct(string $url, ?ClientCertificate $clientCertificate = null) { $requestUrl = parse_url($url); @@ -29,6 +30,8 @@ class Request } } } + + $this->clientCertificate = $clientCertificate; } /** @@ -36,7 +39,17 @@ class Request */ public static function fromResource($resource): static { - return Request::fromString(fread($resource, 1024)); + $request = Request::fromString(fread($resource, 1024)); + + $clientCertificate = null; + $streamParams = stream_context_get_params($resource); + $peerCertificate = $streamParams['options']['ssl']['peer_certificate'] ?? null; + if ($peerCertificate) { + $clientCertificate = new ClientCertificate($peerCertificate); + $request->setClientCertificate($clientCertificate); + } + + return $request; } public static function fromString(string $string): static @@ -67,4 +80,16 @@ class Request return $this; } + + public function getClientCertificate(): ?ClientCertificate + { + return $this->clientCertificate; + } + + public function setClientCertificate(ClientCertificate $clientCertificate): self + { + $this->clientCertificate = $clientCertificate; + + return $this; + } } |