diff --git a/README.md b/README.md index 02a16f5..7b39def 100644 --- a/README.md +++ b/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 -$request = new \Yggverse\Nex\Client\Request( - 'nex://nightfall.city/nex/' // target URL - '46.23.92.144' // resolved IP, skip to use system-wide resolver +var_dump( + $request->getResponse() ); ``` -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 @@ -55,15 +38,5 @@ Get resolved host back #### Request::getPath #### Request::setQuery #### Request::getQuery -#### Request::getResponse - -Execute requested URL and return raw response - -``` php -var_dump( - $request->getResponse() -); -``` - #### Request::getOptions #### Request::setOptions \ No newline at end of file diff --git a/src/Client/Request.php b/src/Client/Request.php index aee0808..16cdfac 100644 --- a/src/Client/Request.php +++ b/src/Client/Request.php @@ -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,