/** * Send HTTP response * * Send the specific X-Sendfile HTTP headers for internal processing by the server. For Nginx and Lighttpd 1.4 * remove the X-Sendfile header and use the specific header instead. * * If the X-Sendfile header is 1 or TRUE, the response path will be used instead of the path supplied in the * header. If X-Sendfile header is 0 or FALSE the header is ignored and removed. * * - Apache : X-Sendfile * - Nginx : X-Accel-Redirect * - Lightttpd : X-LIGHTTPD-send-file (v1.4) or X-Sendfile (v1.5) * * @param KDispatcherResponseInterface $response * @return boolean */ public function send(KDispatcherResponseInterface $response) { if ($response->headers->has('X-Sendfile')) { $path = $response->headers->get('X-Sendfile'); if ($path === true || $path === 1) { $path = $response->getStream()->getPath(); } if (is_file($path)) { $server = strtolower($_SERVER['SERVER_SOFTWARE']); //Nginx uses X-Accel-Redirect header if (strpos($server, 'nginx') !== FALSE) { $path = preg_replace('/' . preg_quote(Koowa::getRootPath(), '/') . '/', '', $path, 1); $response->headers->set('X-Accel-Redirect', $path); $response->headers->remove('X-Sendfile'); } //Lighttpd 1.4 uses X-LIGHTTPD-send-file header if (strpos($server, 'lightttpd/1.4') !== FALSE) { $response->headers->set('X-LIGHTTPD-send-file', $path); $response->headers->remove('X-Sendfile'); } return parent::send($response); } else { $response->headers->remove('X-Sendfile'); } } }