private static function getHttpVars() { if (self::$httpVars === null) { self::$httpVars = array(self::ACCEPT_ENCODING, self::ACCEPT_LANGUAGE, self::USER_AGENT, self::REFERER, self::CONNECTION, self::ACCEPT, self::ACCEPT_CHARSET); } return self::$httpVars; }
private function checkRequestHeader(Gpf_Net_Server_Http_Request $request) { //HTTP/1.1 All Internet-based HTTP/1.1 servers MUST respond with a 400 // (Bad Request) status code to any HTTP/1.1 request message which // lacks a Host header field. if ($request->getVersion() == '1.1' && !$request->existsHeader('Host')) { $response = Gpf_Net_Server_Http_Response::createBadRequest("Host header is missing"); throw new Gpf_Net_Server_Http_RequestException($response); } // if($request->existsHeader('TE')) { // $response = Gpf_Net_Server_Http_Response::createUnimplemented( // "Transfer-Encoding not supported"); // throw new Gpf_Net_Server_Http_RequestException($response); // } if ($request->headerContain('Content-Type', 'multipart/byteranges')) { $response = Gpf_Net_Server_Http_Response::createUnimplemented("Content-Type multipart/byteranges not supported"); throw new Gpf_Net_Server_Http_RequestException($response); } }
/** * * @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; }