blob: 255e29f423e624d7ba46ba628d00c1e03e2492d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<?php
namespace GeminiFoundation;
use GeminiFoundation\Response;
class Client
{
protected string $baseUrl;
public function __construct($baseUrl)
{
$this->baseUrl = $baseUrl;
}
public function request($url): Response
{
$context = stream_context_create(options: [
'ssl' => [
'verify_peer' => false,
],
]);
$connection = stream_socket_client(
address: "tls://{$this->baseUrl}:1965",
context: $context
);
fwrite($connection, "gemini://{$this->baseUrl}{$url}");
$responseString = '';
while (!feof($connection)) {
$responseString .= fgets($connection, 1024);
}
fclose($connection);
$response = Response::fromString($responseString);
return $response;
}
}
|