Beispiel #1
0
 public function setValue($value)
 {
     if (HTTPHeaders::freezed()) {
         return;
     }
     $this->_value = $value;
 }
Beispiel #2
0
 public function header($key, $value)
 {
     if (isset($this->_dict[$key]) && $this->_dict[$key] == HTTPHeader::Singleton && !is_null(HTTPHeaders::header($key))) {
         $header = HTTPHeaders::header($key);
         $header->setValue($value);
         return $header;
     }
     return new HTTPHeader($key, $value);
 }
Beispiel #3
0
     */
    MemPool::instance()->set("bong.url.path", isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/');
    Runtime::loadModule('rom');
    \ROM\BongCurrentUserData::startSession();
    $router = URLAnalyzer::instance()->decide();
    \ROM\BongCurrentUserData::instance()->load();
    if (!\ROM\BongCurrentUserData::instance()->identical()) {
        \ROM\BongCurrentUserData::reset();
    }
    $urlReq = new \ROM\UrlRequest(time(), session_id(), $_SERVER['SCRIPT_NAME']);
    \ROM\BongCurrentUserData::instance()->addUrlRequest($urlReq);
    Runtime::loadModule('dal');
    /*AbstractContentEngine* */
    $engine = $router->engine();
    $engine->run();
    HTTPHeaders::send();
    $response = $engine->response();
    $res = new stdClass();
    $res->url = $r_url;
    $res->res = base64_encode($response);
    $res->checksum = md5($res->res);
    if (!empty($r_checksum) && $r_checksum == $res->checksum) {
        $res->res = '';
    }
    $response = "";
    $response_buff[] = $res;
    \ROM\BongCurrentUserData::instance()->dump();
    Singleton::clearAllInstances();
    //var_dump(Path::instance()->evaluate(":mkt.apps.view.+&controller.-&method.@&method.view.php"));
}
/**/
Beispiel #4
0
 public static function release()
 {
     self::$_freezed = false;
 }
 /**
  * Callback called when new headers are found on the stream.
  *
  * @access public
  * @param  string $data
  * @return void
  */
 public function on_headers($data)
 {
     if ($this->_server->config('VERBOSE') >= 2) {
         file_put_contents($this->_server->config('LOG_FILE'), "REQUEST HEADERS\t" . $this->_start . ":\r\n\r\n" . $data . "\r\n", FILE_APPEND);
     }
     list($start_line, $data) = explode("\r\n", $data, 2);
     list($method, $uri, $version) = explode(' ', $start_line);
     // Make sure this is an HTTP request.
     if (strpos($version, 'HTTP/') !== 0) {
         return;
     }
     // Parse the headers.
     $headers = HTTPHeaders::parse($data);
     // Check for a WebSocket upgrade.
     if ($headers->has('Upgrade') && strtolower($headers->get('Upgrade')) == 'websocket') {
         $this->_request = new WSRequest($this, $method, $uri, $version, $headers, $this->_address);
         if ($headers->has('Sec-WebSocket-Key1') && $headers->has('Sec-WebSocket-Key2')) {
             $this->_stream->read_bytes(8, array($this, 'on_finish_handshake_v76'));
         } else {
             //missed parameter for function handshake
             $this->write($this->_request->handshake());
             call_user_func($this->_request_callback, $this->_request);
             $this->_stream->read_until(chr(255), array($this, 'on_request_body'));
         }
     } else {
         $this->_request = new HTTPRequest($this, $method, $uri, $version, $headers, $this->_address);
     }
     // Increment the request count.
     ++$this->_request_count;
     // Stop the connection from being closed if this is a keep alive request.
     if (!empty($this->_keep_alive_timeoutid)) {
         $this->_server->get_loop()->remove_timeout($this->_keep_alive_timeoutid);
     }
     // Check for a request body.
     $content_length = $headers->get('Content-Length');
     if ($content_length) {
         if ($content_length > IOStream::MAX_BUFFER_SIZE) {
             throw new OverflowException('Content-Length too long');
         }
         if ($headers->get('Expect') == '100-continue') {
             $this->_stream->write("HTTP/1.0 100 (Continue)\r\n\r\n");
         }
         $this->_stream->read_bytes($content_length, array($this, 'on_request_body'));
     } elseif (!$this->_request instanceof WSRequest) {
         call_user_func($this->_request_callback, $this->_request);
     }
 }
 /**
  * Parse a mime body.
  *
  * @access public
  * @param  string $boundry
  * @param  string $data
  * @return void
  */
 private function _parse_mime_body($boundry, $data)
 {
     // Determine the footer length.
     if (mb_substr($data, -2, mb_strlen($data, 'UTF-8'), 'UTF-8') == "\r\n") {
         $footer_length = mb_strlen($boundry, 'UTF-8') + 6;
     } else {
         $footer_length = mb_strlen($boundry, 'UTF-8') + 4;
     }
     // Blow up the body into different parts.
     $parts = explode($boundry, mb_substr($data, 0, -$footer_length, 'UTF-8'));
     foreach ($parts as $part) {
         if (empty($part) || $part == '--') {
             continue;
         }
         $eoh = strpos($part, "\r\n\r\n");
         if ($eoh === false) {
             trigger_error('multipart/form-data missing headers', E_USER_WARNING);
             continue;
         }
         $headers = HTTPHeaders::parse(mb_substr($part, 0, $eoh, 'UTF-8'));
         $name_header = $headers->get('Content-Disposition');
         if (strpos($name_header, 'form-data') !== 0) {
             trigger_error('Invalid multipart/form-data', E_USER_WARNING);
             continue;
         }
         $value = rtrim(mb_substr($part, $eoh + 4, -2, 'UTF-8'));
         $name_values = array();
         foreach (explode(';', mb_substr($name_header, 10, mb_strlen($name_header, 'UTF-8'), 'UTF-8')) as $name_part) {
             list($name, $name_value) = explode('=', trim($name_part), 2);
             $name_values[$name] = utf8_decode(trim($name_value, '"'));
         }
         // Make sure there is a name for the request value.
         if (empty($name_values['name'])) {
             trigger_error('multipart/form-data value missing name', E_USER_WARNING);
             continue;
         }
         // Pull the files out of the requst.
         $name = $name_values['name'];
         if (!empty($name_values['filename'])) {
             // Determine the content type.
             if (!empty($headers['Content-Type'])) {
                 $ctype = $headers['Content-Type'];
             } else {
                 $ctype = 'application/unknown';
             }
             // Create a new entry if we need to.
             if (empty($this->files[$name])) {
                 $this->files[$name] = array();
             }
             $this->files[$name][] = array('filename' => $name_values['filename'], 'body' => $value, 'content_type' => $ctype);
         } else {
             $this->post[$name] = $value;
         }
     }
 }