remove sni dependencies

This commit is contained in:
yggverse 2024-04-21 15:38:14 +03:00
parent a5a3cd730c
commit d33c16842e
2 changed files with 16 additions and 62 deletions

View File

@ -20,41 +20,6 @@ $request = new \Yggverse\Nex\Client\Request(
);
```
**Resolved request (SNI)**
For direct connection provide resolved IP as the second argument
``` php
$request = new \Yggverse\Nex\Client\Request(
'nex://nightfall.city/nex/' // target URL
'46.23.92.144' // resolved IP, skip to use system-wide resolver
);
```
Alternatively, use `setResolvedHost` method of `Request` object before `getResponse`
#### Request::setResolvedHost
``` php
$request->setResolvedHost(
'46.23.92.144'
)
```
* to resolve network address with PHP, take a look on the [net-php](https://github.com/YGGverse/net-php) library!
#### Request::getResolvedHost
Get resolved host back
#### Request::setHost
#### Request::getHost
#### Request::setPort
#### Request::getPort
#### Request::setPath
#### Request::getPath
#### Request::setQuery
#### Request::getQuery
#### Request::getResponse
Execute requested URL and return raw response
@ -65,5 +30,13 @@ var_dump(
);
```
#### Request::setHost
#### Request::getHost
#### Request::setPort
#### Request::getPort
#### Request::setPath
#### Request::getPath
#### Request::setQuery
#### Request::getQuery
#### Request::getOptions
#### Request::setOptions

View File

@ -6,8 +6,6 @@ namespace Yggverse\Nex\Client;
class Request
{
private ?string $_ip = null;
private string $_host;
private int $_port;
private string $_path;
@ -15,7 +13,7 @@ class Request
private array $_options = [];
public function __construct(string $url, ?string $ip = null)
public function __construct(string $url)
{
if ($host = parse_url($url, PHP_URL_HOST))
{
@ -70,13 +68,6 @@ class Request
''
);
}
if ($ip && false !== filter_var($ip, FILTER_VALIDATE_IP))
{
$this->setResolvedHost(
$ip
);
}
}
public function setOptions(array $value): void
@ -129,29 +120,19 @@ 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
?int &$length = 0, // initial response length, do not change without special needs
?int &$code = null, // error code for debug
?string &$message = null, // error message for debug
string &$response = '' // response init, also returning by this method
int $timeout = 30, // socket timeout, useful for offline resources
?int $limit = null, // content length, null for unlimited
?int &$length = 0, // initial response length, do not change without special needs
?int &$code = null, // error code for debug
?string &$message = null, // error message for debug
string &$response = '' // response init, also returning by this method
): ?string
{
$connection = stream_socket_client(
sprintf(
'tcp://%s:%d',
$this->_ip ? $this->_ip : $this->_host,
$this->_host,
$this->_port
),
$code,