Exemplo n.º 1
0
 protected function parseRawBody()
 {
     if ($this->firstLine->isEmptyBody()) {
         $this->post = new ParameterStorage();
     } else {
         $contentType = $this->header->getHeaderValue('HTTP_CONTENT_TYPE', 'text/plain');
         switch ($contentType) {
             case 'application/json':
                 $post = json_decode($this->rawBody);
                 break;
             case 'application/x-www-form-urlencoded':
                 foreach (explode('&', $this->rawBody) as $item) {
                     $pos = strpos($item, '=');
                     $post[urldecode(substr($item, 0, $pos))] = urldecode(substr($item, $pos + 1));
                 }
                 break;
             case 'multipart/form-data':
                 // @todo
                 break;
             case 'text/xml':
                 // @todo
                 break;
             case 'text/html':
             case 'text/plain':
             default:
                 break;
         }
         if (isset($post)) {
             $this->post = new ParameterStorage($post);
         }
     }
 }
Exemplo n.º 2
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]);
         }
     }
 }