Exemple #1
0
 public function sendBuffer($id)
 {
     if (!isset($this->buffers[$id])) {
         return FALSE;
     }
     if (!isset($this->buffers[$id]['raw'])) {
         $this->addAutomaticHeaders($id);
         NginyUS::message('Reply code : $0', array($this->buffers[$id]['code']), E_DEBUG);
         $text = 'HTTP/1.1 ' . $this->buffers[$id]['code'] . " " . $this->replyStr[$this->buffers[$id]['code']] . "\n";
         foreach ($this->buffers[$id]['headers'] as $ref => $header) {
             $text .= $ref . ': ' . $header . "\r\n";
         }
         $text .= "\r\n" . $this->buffers[$id]['data'];
     } else {
         $text = $this->buffers[$id]['raw'];
     }
     $this->sendData($id, $text);
     unset($this->buffers[$id]);
     //$this->closeConnection($id);
 }
Exemple #2
0
 public function addClasses($classes)
 {
     NginyUS::message('Adding classes $0', array(join(', ', $classes)), E_DEBUG);
     $this->classList = array_merge($this->classList, $classes);
 }
 public function setSiteRoot($root)
 {
     NginyUS::message('[$0] New SiteRoot $1', array($this->name, $root), E_DEBUG);
     $this->siteRoot = $root;
 }
Exemple #4
0
 public function parseQuery($id, $query)
 {
     NginyUS::message("New query from \$0", array($id), E_DEBUG);
     if (!$query) {
         return FALSE;
     }
     $data = array();
     socket_getpeername($this->clients[$id], $data['addr']);
     $data['raw'] = $query;
     $query = explode("\r\n\r\n", $query);
     $metadata = explode("\r\n", $query[0]);
     $_POST = array();
     $data['query'] = 'GET';
     $_SERVER = array();
     foreach ($metadata as $row) {
         $row = explode(' ', $row, 2);
         switch ($row[0]) {
             case 'POST':
                 parse_str($query[1], $_POST);
                 if (is_array($_POST)) {
                     NginyUS::message("Received POST data : \$0", array($this->dumpArray($_POST)), E_DEBUG);
                 } else {
                     NginyUS::message("Received POST data : \$0", array($data['rawPOST']), E_DEBUG);
                 }
                 $data['rawPOST'] = $query[1];
             case 'OPTIONS':
             case 'GET':
                 //It's a GET request (main parameter)
                 $_SERVER['REQUEST_METHOD'] = $data['query'] = $row[0];
                 $data['page'] = explode(' ', $row[1]);
                 $data['page'] = $data['page'][0];
                 NginyUS::message('Requested page : $0', array($data['page']), E_DEBUG);
                 break;
             case 'Host:':
                 $host = explode(':', $row[1], 2);
                 $data['host'] = $host[0];
                 $data['port'] = isset($host[1]) ? $host[1] : NULL;
                 break;
             case 'Connection:':
                 if ($row[1] == 'keep-alive') {
                     $data['keep-alive'] = TRUE;
                 }
                 break;
             case 'User-Agent:':
                 array_shift($row);
                 $data['user-agent'] = join(' ', $row);
                 break;
             default:
                 $data[substr($row[0], 0, -1)] = $row[1];
                 break;
         }
         if (isset($row[1])) {
             $_SERVER[substr($row[0], 0, -1)] = $row[1];
         }
     }
     $data['url'] = $data['host'] . $data['page'];
     $this->siteManager->pageCall($id, $data);
 }