I am currently writing a reverse proxy using Symfony (learning purposes)
I am currently able to get text files (HTML, CSS, JS...) but when I'm trying to proxify images, Symfony end up messing up the file.
Here is a compare of the two files, the left one is the file proxified by Symfony
As you can see, there is a whitespace added at the beginning of the file.
When I remove it in notepad++, the image is fine.
Here is my code (I verified, right before returning my response, there is no whitespace) :
$url = "http://10.224.116.191:80";
if(strlen($base64Url) != 0 && $base64Url != "/"){ //base64Url contains an URL
$url .= explode(">>", base64_decode(strtr(ltrim($base64Url, "/"), '-_', '+/')))[1];
}
$proxy = new Proxy($url);
$proxy->createCurl();
$response = new Response();
for($i = 0; $i < count($proxy->__headers()); $i++){
$response->headers->set(array_keys($proxy->__headers())[$i], array_values($proxy->__headers())[$i]);
}
$response->setContent($proxy->__tostring());
return $response;
Proxy comes from http://php.net/manual/en/book.curl.php#90821 where I added headers.
Any reason why this whitespace is added ?