Browse Source

remove sni dependencies

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

35
README.md

@ -20,33 +20,16 @@ $request = new \Yggverse\Nex\Client\Request( @@ -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 @@ -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

35
src/Client/Request.php

@ -6,8 +6,6 @@ namespace Yggverse\Nex\Client; @@ -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 @@ -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 @@ -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 @@ -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,

Loading…
Cancel
Save