/** * 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 DispatcherResponseInterface $response * @return boolean */ public function send(DispatcherResponseInterface $response) { if ($response->headers->has('X-Sendfile')) { $path = $response->headers->get('X-Sendfile'); if ($path === true || $path === 1) { $path = $response->getContent()->getPathname(); } 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(JPATH_ROOT, '/') . '/', '', $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'); } } }
/** * Send HTTP response * * If the format is json, add the padding by inspect the request query for a 'callback' parameter or by using * the default padding if set. * * Don't stop the transport handler chain to allow other transports handlers to continue processing the * response. * * @link http://tools.ietf.org/html/rfc2616 * * @param DispatcherResponseInterface $response * @return boolean */ public function send(DispatcherResponseInterface $response) { $request = $response->getRequest(); //Force to use the json transport if format is json if ($request->getFormat() == 'json') { //If not padding is set inspect the request query. if (empty($this->_padding)) { if ($request->query->has('callback')) { $this->setCallback($request->query->get('callback', 'cmd')); } } if (!empty($this->_padding)) { $response->setContent(sprintf('%s(%s);', $this->_padding, $response->getContent())); } } }