Browse Source

remove sni dependencies

main
yggverse 7 months ago
parent
commit
d33c16842e
  1. 35
      README.md
  2. 23
      src/Client/Request.php

35
README.md

@ -20,33 +20,16 @@ $request = new \Yggverse\Nex\Client\Request(
); );
``` ```
**Resolved request (SNI)** #### Request::getResponse
For direct connection provide resolved IP as the second argument Execute requested URL and return raw response
``` php ``` php
$request = new \Yggverse\Nex\Client\Request( var_dump(
'nex://nightfall.city/nex/' // target URL $request->getResponse()
'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::setHost
#### Request::getHost #### Request::getHost
#### Request::setPort #### Request::setPort
@ -55,15 +38,5 @@ Get resolved host back
#### Request::getPath #### Request::getPath
#### Request::setQuery #### Request::setQuery
#### Request::getQuery #### Request::getQuery
#### Request::getResponse
Execute requested URL and return raw response
``` php
var_dump(
$request->getResponse()
);
```
#### Request::getOptions #### Request::getOptions
#### Request::setOptions #### Request::setOptions

23
src/Client/Request.php

@ -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,

Loading…
Cancel
Save