示例#1
0
 /**
  * Write this output to the scriptlet's response
  *
  * @param  scriptlet.Response $response
  * @param  peer.URL $base
  * @param  string $format
  * @return bool handled
  */
 public function writeTo($response, $base, $format)
 {
     $response->setStatus($this->status);
     $this->writeHead($response, $base, $format);
     // Headers
     foreach ($this->headers as $name => $value) {
         if ('Location' === $name && false === strpos($value, '://')) {
             $url = clone $base;
             $response->setHeader($name, $url->setPath($value)->getURL());
         } else {
             $response->setHeader($name, $value);
         }
     }
     foreach ($this->cookies as $cookie) {
         $response->setCookie($cookie);
     }
     $this->writeBody($response, $base, $format);
     return true;
 }
示例#2
0
 /**
  * Handle exception from scriptlet
  *
  * @param   scriptlet.Response $response
  * @param   lang.Throwable $t
  * @param   int $status
  * @param   bool $trace whether to show stacktrace
  * @return  scriptlet.HttpScriptletResponse
  */
 protected function error($response, \lang\Throwable $t, $status, $trace)
 {
     $package = $this->getClass()->getPackage();
     $errorPage = $package->getResource($package->providesResource('error' . $status . '.html') ? 'error' . $status . '.html' : 'error500.html');
     $response->setProcessed(false);
     $response->setStatus($status);
     $response->setContent(str_replace('<xp:value-of select="reason"/>', $trace ? $t->toString() : $t->getMessage(), $errorPage));
 }