function displayGraphicFile($graphicFileName, $fileType = 'jpeg') { $fileModTime = filemtime($graphicFileName); // Getting headers sent by the client. $headers = getRequestHeaders(); // Checking if the client is validating his cache and if it is current. if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == $fileModTime) { // Client's cache IS current, so we just respond '304 Not Modified'. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fileModTime) . ' GMT', true, 304); } else { // Image not cached or cache outdated, we respond '200 OK' and output the image. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fileModTime) . ' GMT', true, 200); header('Content-type: image/' . $fileType); header('Content-transfer-encoding: binary'); header('Content-length: ' . filesize($graphicFileName)); readfile($graphicFileName); } }
function getRelevantRequestHeaders() { $headers = getRequestHeaders(); $relevantHeaders = array(); foreach ($headers as $header => $value) { if ($header == "X-Authorization") { $relevantHeaders[] = "Authorization: " . rawurldecode($value); } else if ($header == "User-Agent" || $header == "Accept" || $header == "Accept-Language" || $header == "Accept-Charset" || $header == "Content-Type") { $relevantHeaders[] = $header. ": " . $value; } // || $header == "Accept-Encoding" } return $relevantHeaders; }
// Return a 400 Bad Request response and exit header('HTTP/1.1 400 Bad Request'); die; } // Get the endpoint URL $url = $_GET['endpoint'] ? $_GET['endpoint'] : $_POST['endpoint']; // If the URL is empty or is invalid, return the appropriate response $isURLEmpty = empty($url); $isURLValid = filter_var($url, FILTER_VALIDATE_URL) !== false; if ($isURLEmpty || !$isURLValid) { // Return a 400 Bad Request response and exit header('HTTP/1.1 400 Bad Request'); die; } // Get the original request headers $requestHeders = getRequestHeaders(); // Unset the headers that should not be forwarded by the proxy unset($requestHeders['Host']); unset($requestHeders['Content-Length']); unset($requestHeders['Connection']); // Add the Content-Type header based on the original content type if (isset($_SERVER['CONTENT_TYPE'])) { $requestHeders['Content-Type'] = $_SERVER['CONTENT_TYPE']; } // Add the X-Forwarded-For header $requestHeders['X-Forwarded-For'] = isset($requestHeders['X-Forwarded-For']) ? $senderIP . ',' . $requestHeders['X-Forwarded-For'] : $senderIP; // Initialize the data that should be forwarded $data = array(); if ($requestMethod === 'GET') { // Get the original parameters sent via GET $data = $_GET;
/** * Odesle hotovy souboru * @param string $file */ function sendFile($file) { if (!is_file($file)) { send404(); } $fileModTime = max(filemtime($file), filectime($file)); $headers = getRequestHeaders(); if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == $fileModTime) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fileModTime) . ' GMT', true, 304); } else { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $fileModTime) . ' GMT', true, 200); header('Content-type: image/jpeg'); header('Content-transfer-encoding: binary'); header('Content-length: ' . filesize($file)); readfile($file); } exit; }