Skip to content

Commit

Permalink
fix: cannot encode full url on send request
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 11, 2023
1 parent 4cfd9e1 commit 05373b7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ public function getArrayData(): array
}

/**
* get JSON body as array data
* get JSON body and decode to array data
*
* @return array
*/
Expand Down Expand Up @@ -939,11 +939,11 @@ public function getJsonObject(): bool|stdClass
*
* @param object $obj
*
* @return void
* @return object
*/
public function bindBodyTo(object $obj): void
public function bindBodyTo(object $obj): object
{
Obj::init($obj, $this->getArrayData());
return Obj::init($obj, $this->getArrayData());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function trace(string $url, array $params = [], array $headers = [], arra
* Send request to remote URL
*
* @param string $url
* @param array|string|null $data
* @param array|string|null $data Body data or query data.
* @param string $method
* @param array $headers
* @param array $options = AbstractClient::$defaultOptions
Expand Down
6 changes: 2 additions & 4 deletions src/Curl/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PhpPkg\Http\Client\Traits\ParseRawResponseTrait;
use Toolkit\Stdlib\Arr\ArrayHelper;
use Toolkit\Stdlib\Helper\Assert;
use Toolkit\Stdlib\Str\UrlHelper;
use function array_merge;
use function curl_close;
use function curl_errno;
Expand Down Expand Up @@ -46,7 +45,6 @@
use const CURLAUTH_BASIC;
use const CURLE_COULDNT_CONNECT;
use const CURLE_COULDNT_RESOLVE_HOST;
use const CURLE_HTTP_NOT_FOUND;
use const CURLE_HTTP_POST_ERROR;
use const CURLE_OPERATION_TIMEOUTED;
use const CURLE_READ_ERROR;
Expand Down Expand Up @@ -118,7 +116,7 @@ class CurlClient extends AbstractClient implements CurlClientInterface
private static array $canRetryErrorCodes = [
CURLE_COULDNT_RESOLVE_HOST,
CURLE_COULDNT_CONNECT,
CURLE_HTTP_NOT_FOUND,
// CURLE_HTTP_NOT_FOUND,
CURLE_READ_ERROR,
CURLE_OPERATION_TIMEOUTED,
CURLE_HTTP_POST_ERROR,
Expand Down Expand Up @@ -402,7 +400,7 @@ protected function prepareRequest(string $url, mixed $data, array $headers, arra
CurlUtil::setMethodToOption($curlOptions, $method);

// set request url
$curlOptions[CURLOPT_URL] = UrlHelper::encode2($url);
$curlOptions[CURLOPT_URL] = $url;

// append http headers
if ($headers = array_merge($this->headers, $options['headers'], $headers)) {
Expand Down
4 changes: 1 addition & 3 deletions src/FOpenClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PhpPkg\Http\Client\Traits\ParseRawResponseTrait;
use PhpPkg\Http\Client\Traits\StreamContextBuildTrait;
use Throwable;
use Toolkit\Stdlib\Str\UrlHelper;
use function array_merge;
use function fclose;
use function feof;
Expand Down Expand Up @@ -101,9 +100,8 @@ public function request(
try {
$ctx = $this->buildStreamContext($url, $headers, $options, $data);

$fullUrl = UrlHelper::encode2($this->fullUrl);
// send request
$this->handle = fopen($fullUrl, 'rb', false, $ctx);
$this->handle = fopen($this->fullUrl, 'rb', false, $ctx);
} catch (Throwable $e) {
throw new ClientException($e->getMessage(), $e->getCode(), $e);
}
Expand Down
3 changes: 1 addition & 2 deletions src/FileClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PhpPkg\Http\Client\Traits\ParseRawResponseTrait;
use PhpPkg\Http\Client\Traits\StreamContextBuildTrait;
use Throwable;
use Toolkit\Stdlib\Str\UrlHelper;
use function array_merge;
use function file_get_contents;
use function function_exists;
Expand Down Expand Up @@ -70,7 +69,7 @@ public function request(

try {
$reqCtx = $this->buildStreamContext($url, $headers, $options, $data);
$fullUrl = UrlHelper::encode2($this->fullUrl);
$fullUrl = $this->fullUrl;

// send request
$this->responseBody = file_get_contents($fullUrl, false, $reqCtx);
Expand Down

0 comments on commit 05373b7

Please sign in to comment.