I have a Controller that must forward the received request (changing some query parameters) to another server, and returns it's response (with same headers, status and body).
I decided to use HttpClient for doing that.
The problem is that HttpClient converts the content (i.e.: deflating gzip requests), and it breaks the output response.
Here is part of the example:
$response = $client->request($request->getMethod(), $extUrl, [
'headers' => $reqHeaders,
'timeout' => 45,
'verify_host' => false,
'verify_peer' => false,
'body' => $request->getContent(),
]);
#response data
$body = $response->getContent(false);
$statusCode = $response->getStatusCode();
$headers = $response->getHeaders(false);
return new Response($body, $statusCode, $headers);
Considering the second server returns a gzipped content, the response is broken, because it would keep the response header (content-type) but the $body will not be exactly the same, because HttpClient do me the favor of deflate the content.
The question is: is there a way to tell HttpClient to do not touch in my response body?
Or: is there a better way to make this "proxy" controller action?