Esempio n. 1
0
 protected function _error($message = null, $statusCode = self::REST_STATUS_BAD_REQUEST)
 {
     if (is_numeric($statusCode)) {
         $statusCode = intval($statusCode);
     }
     $this->_response->clearAllHeaders()->clearBody();
     $this->_response->setHttpResponseCode(intval($statusCode))->setHeader('Content-Type', 'application/json', true);
     if (!empty($message)) {
         $this->_response->setBody(json_encode($message));
     }
     $this->_response->sendResponse();
     exit;
 }
Esempio n. 2
0
 public function sendResponse()
 {
     $gzip = isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false;
     $gzip &= !headers_sent();
     if ($gzip) {
         header('Content-Encoding: gzip');
         ob_start("ob_gzhandler");
     }
     parent::sendResponse();
     if ($gzip) {
         ob_end_flush();
     }
 }
Esempio n. 3
0
 /**
  * Send response to browser with json content type
  */
 public function sendResponse()
 {
     $this->_response = Mage::app()->getResponse();
     //check redirect
     if ($this->_response->isRedirect()) {
         $headers = $this->_response->getHeaders();
         $redirect = '';
         foreach ($headers as $header) {
             if ("Location" == $header["name"]) {
                 $redirect = $header["value"];
                 break;
             }
         }
         if ($redirect) {
             $this->setRedirect($redirect);
         }
     }
     $this->_response->clearHeaders();
     $this->_response->setHeader('Content-Type', 'application/json');
     $this->_response->clearBody();
     $this->_response->setBody($this->toJson());
     $this->_response->sendResponse();
     exit;
 }
Esempio n. 4
0
 public function __construct($msg = '', $code = 0, Exception $previous = null)
 {
     // just pass ahead if it was throw from the CLI
     if (php_sapi_name() == "cli") {
         return parent::__construct($msg, (int) $code, $previous);
     } else {
         parent::__construct($msg, (int) $code, $previous);
         $response = new Zend_Controller_Response_Http();
         $response->setHttpResponseCode(500);
         ob_get_clean();
         ob_start();
         require APPLICATION_PATH . "/layout/scripts/exception.phtml";
         $outputBuffer = ob_get_clean();
         $response->setBody($outputBuffer);
         $response->sendResponse();
         trigger_error($msg, E_USER_ERROR);
         exit;
     }
 }
Esempio n. 5
0
 public function __construct($app)
 {
     parent::__construct($app);
     date_default_timezone_set('America/Lima');
     $this->bootstrap('multidb');
     /* ejecuta un recurso */
     $db = $this->getPluginResource('multidb')->getDb('db');
     /* obtiene los datos del recurso */
     Zend_Db_Table::setDefaultAdapter($db);
     /* registra el adaptador */
     Zend_Registry::set('db', $db);
     /*registra la clase adaptadora*/
     Zend_Form::setDefaultTranslator(new Zend_Translate('array', APPLICATION_PATH . '/configs/lang/es.php', 'es'));
     $this->getResourceLoader()->addResourceType('entity', 'entitys/', 'Entity');
     $this->getResourceLoader()->addResourceType('service', 'services/', 'Service');
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Type', 'text/html; charset=utf-8')->setHeader('Accept-Encoding', 'gzip, deflate')->setHeader('Expires', 'max-age=' . 20, true)->setHeader('Cache-Control', 'private', 'must-revalidate')->setHeader('Pragma', 'no-cache', true);
     $response->sendResponse();
 }
Esempio n. 6
0
 /**
  * Used to send the server response to the client.
  */
 public static function sendResponse(Zend_Controller_Response_Http $response)
 {
     // Set the response headers.
     $response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
     // Send the response to the client.
     $response->sendResponse();
 }
Esempio n. 7
0
 /**
  * Performs a HTTP redirection to specified URL with additional data.
  * It may generate redirected request using GET or POST HTTP method.
  * The function never returns.
  *
  * @param string $url URL to redirect to
  * @param array $params additional variable/value pairs to send
  * @param Zend_Controller_Response_Abstract $response
  * @param string $method redirection method ('GET' or 'POST')
  */
 public static function redirect($url, $params = null, Zend_Controller_Response_Abstract $response = null, $method = 'GET')
 {
     $url = Zend_OpenId::absoluteUrl($url);
     $body = "";
     if (null === $response) {
         #require_once "Zend/Controller/Response/Http.php";
         $response = new Zend_Controller_Response_Http();
     }
     if ($method == 'POST') {
         $body = "<html><body onLoad=\"document.forms[0].submit();\">\n";
         $body .= "<form method=\"POST\" action=\"{$url}\">\n";
         if (is_array($params) && count($params) > 0) {
             foreach ($params as $key => $value) {
                 $body .= '<input type="hidden" name="' . $key . '" value="' . $value . "\">\n";
             }
         }
         $body .= "<input type=\"submit\" value=\"Continue OpenID transaction\">\n";
         $body .= "</form></body></html>\n";
     } else {
         if (is_array($params) && count($params) > 0) {
             if (strpos($url, '?') === false) {
                 $url .= '?' . self::paramsToQuery($params);
             } else {
                 $url .= '&' . self::paramsToQuery($params);
             }
         }
     }
     if (!empty($body)) {
         $response->setBody($body);
     } else {
         if (!$response->canSendHeaders()) {
             $response->setBody("<script language=\"JavaScript\"" . " type=\"text/javascript\">window.location='{$url}';" . "</script>");
         } else {
             $response->setRedirect($url);
         }
     }
     $response->sendResponse();
     if (self::$exitOnRedirect) {
         exit;
     }
 }
Esempio n. 8
0
 public function sendResponse()
 {
     Mage::dispatchEvent('http_response_send_before', array('response' => $this));
     return parent::sendResponse();
 }
Esempio n. 9
0
 public static function sendResponse(Zend_Controller_Response_Http $response)
 {
     $response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
     $response->sendResponse();
 }
Esempio n. 10
0
$logExtra = array();
$logMessage = false;
try {
    if (!$processor->validateRequest($logMessage)) {
        $logType = 'error';
        $response->setHttpResponseCode(500);
    } else {
        if (!$processor->validatePreConditions($logMessage)) {
            $logType = 'error';
        } else {
            $logType = 'info';
            $logMessage = $processor->processTransaction();
        }
    }
    if (is_array($logMessage)) {
        $temp = $logMessage;
        list($logType, $logMessage) = $temp;
    }
} catch (Exception $e) {
    $response->setHttpResponseCode(500);
    XenForo_Error::logException($e);
    $logType = 'error';
    $logMessage = 'Exception: ' . $e->getMessage();
    $logExtra['_e'] = $e;
}
if ($logType) {
    $processor->log($logType, $logMessage, $logExtra);
}
$response->setBody(htmlspecialchars($logMessage));
$response->sendResponse();
Esempio n. 11
0
 public static function sendResponse(Zend_Controller_Response_Http $response)
 {
     $response->sendResponse();
 }
Esempio n. 12
0
 /**
  * Send the response, including all headers, rendering exceptions if so
  * requested.
  *
  * @return void
  */
 public function sendResponse()
 {
     $this->sendVary();
     parent::sendResponse();
 }
Esempio n. 13
0
 protected function _sendResponse($httpCode, $code, $message)
 {
     // TODO Why is sometimes sending response twice??? :S
     if (self::$responseSent) {
         return;
     }
     if (!($response = Zend_Controller_Front::getInstance()->getResponse())) {
         $response = new Zend_Controller_Response_Http();
     }
     $response->setHttpResponseCode($httpCode);
     if (!$response->getBody()) {
         $body = array('code' => $code, 'message' => $message);
         $response->setBody(Zend_Json::encode($body));
     }
     if ($response->canSendHeaders()) {
         $response->clearHeaders();
         $response->setHeader('Content-Type', 'application/json');
         $response->sendResponse();
         self::$responseSent = true;
     }
     exit;
 }
Esempio n. 14
0
 /**
  * @see AM_Handler_Export_Storage_Interface::sendPackage()
  * @throws AM_Handler_Export_Storage_Exception
  */
 public function sendPackage()
 {
     $sFilePath = $this->_buildPackagePath() . DIRECTORY_SEPARATOR . $this->getPackage()->getPackageName();
     $sFileName = $this->getPackage()->getPackageDownloadName();
     if (!file_exists($sFilePath)) {
         throw new AM_Handler_Export_Storage_Exception(sprintf('File "%s" not found', $sFilePath));
     }
     $oResponse = new Zend_Controller_Response_Http();
     $oResponse->setHttpResponseCode(200);
     $oRequest = new Zend_Controller_Request_Http();
     $iFileSize = filesize($sFilePath);
     $sFileMtime = @gmdate("D, d M Y H:i:s", @filemtime($sFilePath)) . " GMT";
     $rFile = @fopen($sFilePath, 'rb');
     $sRange = $oRequest->get('HTTP_RANGE');
     //Trying to resume download according to the HTTP_RANGE header
     if (preg_match('/bytes=(\\d+)-(\\d*)/i', $sRange, $matches)) {
         $sRange = $matches[1];
     } else {
         $sRange = false;
     }
     if ($sRange) {
         fseek($rFile, $sRange);
         $oResponse->setHttpResponseCode(206);
         $oResponse->setHeader('Content-Range', sprintf('bytes %d-%d/%d', $sRange, $iFileSize - 1, $iFileSize));
     }
     $oResponse->setHeader('Content-Disposition', 'attachment; filename=' . $sFileName)->setHeader('Content-Length', $iFileSize - $sRange)->setHeader('Content-Type', 'application/octet-stream')->setHeader('Accept-Ranges', 'bytes')->setHeader('Last-Modified', $sFileMtime);
     while (!feof($rFile)) {
         $sBuffer = fread($rFile, 2048);
         $oResponse->appendBody($sBuffer);
     }
     fclose($rFile);
     $oResponse->sendResponse();
 }