Ejemplo n.º 1
0
 public function onAppend()
 {
     $this->bind->getData('client')->getTimestamp()->update(ServerTimestampType::RequestLast);
     $buffer = $this->bind->getBuffer();
     if (!$this->firstLine) {
         if (false !== ($pos = $buffer->find("\r\n"))) {
             $rawFirstLine = $buffer->pop($pos, 2);
             $this->firstLine = FirstLine::factory($rawFirstLine);
         }
     }
     if ($this->firstLine && !$this->header) {
         if (false !== ($pos = $buffer->find("\r\n\r\n"))) {
             $rawHeader = $buffer->pop($pos, 4);
             $this->header = HttpHeader::factory($rawHeader);
         }
     }
     if ($this->header) {
         $httpContentLength = $this->header['HTTP_CONTENT_LENGTH'];
         if (($isEmptyBody = $this->firstLine->isEmptyBody()) || $buffer->size() >= $httpContentLength) {
             $rawBody = !$isEmptyBody ? $buffer->pop($httpContentLength) : '';
             $request = Request::factory(['firstLine' => $this->firstLine, 'header' => $this->header, 'rawBody' => $rawBody]);
             $this->firstLine = null;
             $this->header = null;
             $this->bind->dispatch($request);
             $this->event->fire('http.pipeline:send', [$request]);
         }
     }
 }
Ejemplo n.º 2
0
 public static function factory($rawHttpRequest = null)
 {
     if (is_string($rawHttpRequest)) {
         if (false === ($firstLinePos = strpos($rawHttpRequest, "\r\n"))) {
         }
         $rawFirstLine = substr($rawHttpRequest, 0, $firstLinePos);
         $firstLine = FirstLine::factory($rawFirstLine);
         if (false === ($rawHeaderEndPos = strpos($rawHttpRequest, "\r\n\r\n", $firstLinePos + 2))) {
         }
         $rawHeader = substr($rawHttpRequest, $firstLinePos + 2, $rawHeaderEndPos - $firstLinePos - 2);
         $header = Header::factory($rawHeader);
         $httpContentLength = $header->getHeader('HTTP_CONTENT_LENGTH', null);
         if (!$firstLine->isEmptyBody()) {
             $rawBody = substr($rawHttpRequest, $rawHeaderEndPos + 4, $httpContentLength);
         } else {
             $rawBody = '';
         }
     } else {
         $firstLine = $rawHttpRequest['firstLine'];
         $header = $rawHttpRequest['header'];
         $rawBody = $rawHttpRequest['rawBody'];
     }
     return new static($firstLine, $header, null, null, null, null, $rawBody);
 }