Request API endpoint with internal request with Guzzle don't return transformed data
- Dominant language
- PHP
- Stars
- 9.4k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 5.6.26
| Package version | 2.0.0-alpha2
| PHP version | 7.1.6
#### Actual Behaviour
I have an API endpoint in witch I'm requesting another endpoint with internal request. I want transformed data to be returned from that endpoint, so I'm using ->raw() option. Everything working fine when I request this endpoint with internal request from Postman, but when I'm making calls from another application (using Guzzle client) the request return untransformed data.
#### Expected Behaviour
Endpoint with internal request which has ->raw() option should return transformed data.
#### Steps to Reproduce
1. I have a GET API endpoint pointing to controller method with code:
```
app('Dingo\Api\Dispatcher')
->raw()
->be($user)
->once()
->with($request->all())
->get('some/resource');
```
2. I'm requesting that endpoint from another application using Guzzle client
```
$client = new \GuzzleHttp\Client([
'base_uri' => ...,
'headers' => ...,
'verify' => ...,
'http_errors' => false,
]);
$response = $client->request('GET', );
```
3. Response has untransformed data.
#### Possible Solutions
I debugged Dispatcher class and came to conclusion that when I'm requesting endpoint with Postman the dispatch() method is invoked once but when I'm making the request with Guzzle this method is called several times, like there are some additional internal requests and some of this requests don't have $this->raw set to true (despite of adding ->raw() option to my internal call). I took a look at the refreshRequestStack() method code and there is this code which reset raw parameter:
```
$this->raw = false;
```
When I commented this out the internal call works as expected returning transformed data. Unfortunately extending Dispatcher class not working for me.
Contributor guide
Assessment
This issue has not been assessed yet.