public function feed($data) { $this->buffer .= $data; if (!$this->request && false !== strpos($this->buffer, "\r\n\r\n")) { // Extract the header from the buffer // in case the content isn't complete list($headers, $this->buffer) = explode("\r\n\r\n", $this->buffer, 2); // Fail before parsing if the if (strlen($headers) > $this->maxSize) { $this->headerSizeExceeded(); return; } $this->request = gPsr\parse_request($headers . "\r\n\r\n"); } // if there is a request (meaning the headers are parsed) and // we have the right content size, we can finish the parsing if ($this->request && $this->isRequestComplete()) { $body = substr($this->buffer, 0, $this->length); // create a stream for the body. $stream = new BufferedStream(); $stream->write($body); // add stream to the request. $this->request = $this->request->withBody($stream); // create server request object $this->request = new ServerRequest($this->request); // todo this should really belong in the header parsing. clean this up. $parsedQuery = []; $queryString = $this->request->getUri()->getQuery(); if ($queryString) { parse_str($queryString, $parsedQuery); if (!empty($parsedQuery)) { $this->request = $this->request->withQueryParams($parsedQuery); } } // add server request information to the request object. $this->request = $this->parseBody($body, $this->request); $this->emit('headers', array($this->request)); $this->removeAllListeners(); $this->request = null; return; } // fail if the header hasn't finished but it is already too large if (!$this->request && strlen($this->buffer) > $this->maxSize) { $this->headerSizeExceeded(); return; } }