mirror of
https://github.com/YGGverse/gemini-php.git
synced 2026-04-01 01:15:28 +00:00
add resolved request support
This commit is contained in:
parent
54ad13e9a5
commit
06238a4ce3
2 changed files with 78 additions and 32 deletions
|
|
@ -6,6 +6,8 @@ namespace Yggverse\Gemini\Client;
|
|||
|
||||
class Request
|
||||
{
|
||||
private ?string $_ip = null;
|
||||
|
||||
private string $_host;
|
||||
private int $_port;
|
||||
private string $_path;
|
||||
|
|
@ -20,7 +22,7 @@ class Request
|
|||
]
|
||||
];
|
||||
|
||||
public function __construct(string $url)
|
||||
public function __construct(string $url, ?string $ip = null)
|
||||
{
|
||||
if ($host = parse_url($url, PHP_URL_HOST))
|
||||
{
|
||||
|
|
@ -75,6 +77,13 @@ class Request
|
|||
''
|
||||
);
|
||||
}
|
||||
|
||||
if ($ip && false !== filter_var($ip, FILTER_VALIDATE_IP))
|
||||
{
|
||||
$this->setResolvedHost(
|
||||
$ip
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function setOptions(array $value): void
|
||||
|
|
@ -127,6 +136,16 @@ class Request
|
|||
return $this->_query;
|
||||
}
|
||||
|
||||
public function setResolvedHost(?string $value): void
|
||||
{
|
||||
$this->_ip = $value;
|
||||
}
|
||||
|
||||
public function getResolvedHost(): ?string
|
||||
{
|
||||
return $this->_ip;
|
||||
}
|
||||
|
||||
public function getResponse(
|
||||
int $timeout = 30, // socket timeout, useful for offline resources
|
||||
?int $limit = null, // content length, null for unlimited
|
||||
|
|
@ -139,7 +158,7 @@ class Request
|
|||
$connection = stream_socket_client(
|
||||
sprintf(
|
||||
'tls://%s:%d',
|
||||
$this->_host,
|
||||
$this->_ip ? $this->_ip : $this->_host,
|
||||
$this->_port
|
||||
),
|
||||
$code,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue