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 #### Request::getResponse
Execute requested URL and return raw response 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::getOptions
#### Request::setOptions #### Request::setOptions

View file

@ -6,8 +6,6 @@ namespace Yggverse\Nex\Client;
class Request class Request
{ {
private ?string $_ip = null;
private string $_host; private string $_host;
private int $_port; private int $_port;
private string $_path; private string $_path;
@ -15,7 +13,7 @@ class Request
private array $_options = []; private array $_options = [];
public function __construct(string $url, ?string $ip = null) public function __construct(string $url)
{ {
if ($host = parse_url($url, PHP_URL_HOST)) 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 public function setOptions(array $value): void
@ -129,16 +120,6 @@ class Request
return $this->_query; return $this->_query;
} }
public function setResolvedHost(?string $value): void
{
$this->_ip = $value;
}
public function getResolvedHost(): ?string
{
return $this->_ip;
}
public function getResponse( public function getResponse(
int $timeout = 30, // socket timeout, useful for offline resources int $timeout = 30, // socket timeout, useful for offline resources
?int $limit = null, // content length, null for unlimited ?int $limit = null, // content length, null for unlimited
@ -151,7 +132,7 @@ class Request
$connection = stream_socket_client( $connection = stream_socket_client(
sprintf( sprintf(
'tcp://%s:%d', 'tcp://%s:%d',
$this->_ip ? $this->_ip : $this->_host, $this->_host,
$this->_port $this->_port
), ),
$code, $code,