Exemplo n.º 1
0
 /**
  *
  * @param unknown_type $text
  * @return Gpf_Net_Server_Http_Response
  */
 public static function createUnimplemented($text)
 {
     $response = new Gpf_Net_Server_Http_Response(501);
     $response->setConnection("close");
     $response->setBody($text);
     return $response;
 }
Exemplo n.º 2
0
 private function serveRequest(Gpf_Net_Server_Http_Request $request)
 {
     $method = $request->getMethod();
     if (!method_exists($this, $method)) {
         // not implemented
         //TODO: refactor
         $response = new Gpf_Net_Server_Http_Response(501);
         $response->setContentType("text/html");
         $response->setConnection("close");
         throw new Gpf_Net_Server_Http_RequestException($response);
     }
     if (!$this->isMethodAllowed($method)) {
         // not allowed
         //TODO: refactor
         $response = new Gpf_Net_Server_Http_Response(405);
         $response->setContentType("text/html");
         $response->setConnection("close");
         throw new Gpf_Net_Server_Http_RequestException($response);
     }
     $response = $this->{$method}($request);
     if ($response === null) {
         return;
     }
     $this->send($response);
 }
Exemplo n.º 3
0
 /**
  *
  * @param Gpf_Net_Server_Http_Request $request
  * @return Gpf_Net_Server_Http_Response
  */
 public function handle(Gpf_Net_Server_Http_Request $request)
 {
     $file = new Gpf_Io_File($this->getFileName($request->getPath()));
     $fileETag = $this->computeEtag($file);
     Gpf_Log::debug($request->toString());
     if ($this->isCacheableFile($file) && $request->ifNoneMatch($fileETag)) {
         $response = new Gpf_Net_Server_Http_Response(304, $file);
         $response->setConnection('Keep-Alive');
         $response->setBody("Not Modified");
         $response->setETag($fileETag);
         Gpf_Log::debug($this->_sys("Resource not modified, returned 304 for %s", $request->getPath()));
         return $response;
     }
     //TODO load file from memory cache if available and not from file
     // - but I'm not sure if file cache will help - it can just use quite huge amount of server memory
     try {
         $file->open();
     } catch (Gpf_Exception $e) {
         $response = new Gpf_Net_Server_Http_Response(404);
         $response->setBody('File not found');
         Gpf_Log::info($e->getMessage());
         return $response;
     }
     $response = new Gpf_Net_Server_Http_StreamResponse(200, $file);
     $response->setConnection('Keep-Alive');
     $response->setContentType(self::getContentType(self::getFileExtension($request->getPath())));
     $response->setContentLength($file->getSize());
     if ($this->isCacheableFile($file)) {
         $response->setETag($fileETag);
     }
     Gpf_Log::debug($this->_sys("Return static file %s" . $request->getPath()));
     return $response;
 }