Skip to content

Commit 4b0f8fa

Browse files
committed
Get rid off (un)serialize Response to allow arbitrary binary data transfer
fix #1
1 parent 1f0a284 commit 4b0f8fa

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

src/AbstractProxy.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct(int $numberOfInternalProxyAfterThisProxy, ?IRequestD
8181
}
8282

8383
/**
84-
* Process Request and print Response
84+
* Process Request and print Response, please dont print anything after or we will add exit() :)
8585
* @param Request $request if NULL Request will be parsed from POST data using requestPostKey
8686
*/
8787
public function process(Request $request = null): void
@@ -158,7 +158,7 @@ protected function forward(string $url, array $additionalData = [])
158158

159159
$response = $this->curlRequestFactory->fetchResponse($this->createCommunicationRequest($url, $postFields));
160160

161-
$this->setResponseFromSerializedString($response->getBody());
161+
$this->setResponseFromSerialized($response);
162162
}
163163

164164
/**
@@ -194,20 +194,34 @@ private function createCommunicationRequest(string $url, array $postFields): Req
194194
*/
195195
protected function printResponse()
196196
{
197-
echo serialize($this->getResponse());
197+
$body = $this->getResponse()->getBody();
198+
$this->getResponse()->setBody('');
199+
header('x-solcloud-proxy: ' . base64_encode(serialize($this->getResponse())));
200+
echo $body;
201+
$this->getResponse()->setBody($body);
198202
}
199203

200204
/**
201-
* Try to set Response by unserializing $serializedResponseString
205+
* Try to set "target" Response by inspecting $internalResponse
202206
* @throws ProxyException or subclass - if unserializition failed or Response has exception
203207
*/
204-
protected function setResponseFromSerializedString(string $serializedResponseString): void
208+
protected function setResponseFromSerialized(Response $internalResponse): void
205209
{
206-
$response = @unserialize($serializedResponseString);
210+
$data = $internalResponse->getLastHeadersFormatted()['x-solcloud-proxy'] ?? false;
211+
if ($data) {
212+
$data = base64_decode($data, true);
213+
}
214+
if ($data === false) {
215+
throw new ProxyException('Decoding of Response failed');
216+
}
217+
218+
$response = @unserialize($data);
207219
if ($response === false) {
208220
throw new ProxyException('Unserialization of Response failed');
209221
}
210222

223+
/** @var Response $response */
224+
$response->setBody($internalResponse->getBody());
211225
$this->setResponse($response);
212226
}
213227

0 commit comments

Comments
 (0)