Ejemplo n.º 1
0
 /**
  * Send a response to the browser
  * 
  * @param integer $status Status code
  * @param string  $html   HTML code to send
  * @param string  $contentType content code to send
  * @return void
  */
 public function respond($status, $html, $contentType)
 {
     $statusMsg = "Internal Server Error";
     if (isset(WebBotServer::$errorCodes[$status])) {
         $statusMsg = WebBotServer::$errorCodes[$status];
     }
     // Transfer-Encoding: chunked
     // http://en.wikipedia.org/wiki/Chunked_transfer_encoding
     // dechex(len)\r\n CHUNK \r\n0
     $this->handler->put("HTTP/1.1 {$status} {$statusMsg}\r\n");
     $this->handler->put("Content-type: {$contentType}\r\n");
     $this->handler->put("Content-Length: " . strlen($html) . "\r\n");
     $this->handler->put("Connection: Close\r\n");
     $this->handler->put("Date: " . date('r') . "\r\n");
     $this->handler->put("Server: neotor/1.1 WebBot/0.1\r\n");
     $this->handler->put("\r\n");
     $this->handler->put($html);
     $this->handler->close();
 }
Ejemplo n.º 2
0
 public function quit()
 {
     $this->handler->close();
     return;
 }
Ejemplo n.º 3
0
 /**
  * Gets called when there's new data from the browser, waits for a
  * complete request, then creates a WebBotRequest
  * 
  * @param SocketHandlerInterface $handler The handler
  * @param string                 $data    New data
  * @param integer                $error   0 if no error
  * @return void
  */
 public function clientData($handler, $data, $error)
 {
     if ($error > 0) {
         if (false !== $handler->request) {
             $handler->request->close();
         }
         return true;
     }
     if (false !== $handler->request) {
         $handler->request->data($data);
         return true;
     }
     if (false === $handler->data) {
         $handler->data = '';
     }
     $handler->data .= $data;
     if (strlen($handler->data) > 16384) {
         // Kill any request larger than 16KiB
         $handler->close();
         return true;
     }
     if (false !== strpos($handler->data, "\r\n\r\n") || false !== strpos($handler->data, "\n\n") || false !== strpos($handler->data, "\r\r")) {
         $handler->request = new WebBotRequest($this, $handler, $handler->data);
         return true;
     }
     return false;
 }