Skip to content

Commit

Permalink
Merge pull request #11 from mingyoung/patch-1
Browse files Browse the repository at this point in the history
real raw response
  • Loading branch information
overtrue authored Jan 13, 2019
2 parents 76ae3be + fc3f2ad commit 7270d64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Overtrue\Http;

use GuzzleHttp\Client as GuzzleClient;
use Overtrue\Http\Responses\Response;
use Overtrue\Http\Traits\HasHttpRequests;

/**
Expand Down Expand Up @@ -140,7 +139,9 @@ public function request(string $uri, string $method = 'GET', array $options = []

$response = $this->performRequest($uri, $method, $options);

return $returnRaw ? $response : $this->castResponseToType($response, $this->config->getOption('response_type'));
return $this->castResponseToType(
$response, $returnRaw ? 'raw' : $this->config->getOption('response_type')
);
}

/**
Expand All @@ -152,7 +153,7 @@ public function request(string $uri, string $method = 'GET', array $options = []
*/
public function requestRaw(string $url, string $method = 'GET', array $options = [])
{
return Response::buildFromPsrResponse($this->request($url, $method, $options, true));
return $this->request($url, $method, $options, true);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Traits/ResponseCastable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ trait ResponseCastable
*/
protected function castResponseToType(ResponseInterface $response, $type = null)
{
if ('raw' === $type) {
return $response;
}

$response = Response::buildFromPsrResponse($response);
$response->getBody()->rewind();

Expand All @@ -41,8 +45,6 @@ protected function castResponseToType(ResponseInterface $response, $type = null)
return $response->toArray();
case 'object':
return $response->toObject();
case 'raw':
return $response;
}
}

Expand Down

0 comments on commit 7270d64

Please sign in to comment.