I'm trying to proxy a request from A site to B site, using guzzle.
-> send HTTP GET to A
...As data is coming from A...
-> send HTTP PUT to B Forward all content using streams.
How to do it? I tried this way, no data is sent to B:
$url_origin = '10.10.10.10/origin';
$url_dest = '20.20.20.20/dest';
$client_origin = new GuzzleClient();
$client_destination = new GuzzleClient();
$response_origin = $client_origin->request('GET', $url_origin, ['stream'=>true]);
$body_origin = $response_origin->getBody();
$dest_stream = Psr7\Utils::streamFor();
$response_dest = $client_destination->request('PUT', $url_dest,
[
'body' => $dest_stream,
'stream'=>true,
'read_timeout' => 10,
'Content-Type' => 'application/octet-stream'
]);
while (!$body_origin->eof())
{
$data = $body_origin->read(1024*1024);
$dest_stream->write($data);
}
Then tried using only streams:
$url_origin = '10.10.10.10/origin';
$url_dest = '20.20.20.20/dest';
$client_origin = new GuzzleClient();
$client_destination = new GuzzleClient();
$stream = Psr7\Utils::streamFor();
$client_destination->request('PUT', $url_dest,
[
'body' => $stream,
'stream' => true,
'Content-Type' => 'application/octet-stream'
]);
$response_origin = $client_origin->request('GET', $url_origin, ['sink' => $stream]);
Same result... Any idea?