|
3 | 3 | namespace React\Http\Io; |
4 | 4 |
|
5 | 5 | use Evenement\EventEmitter; |
| 6 | +use Psr\Http\Message\ServerRequestInterface; |
6 | 7 | use RingCentral\Psr7 as g7; |
7 | 8 | use Exception; |
8 | 9 |
|
@@ -44,21 +45,24 @@ public function feed($data) |
44 | 45 |
|
45 | 46 | if (false !== $endOfHeader) { |
46 | 47 | try { |
47 | | - $this->parseAndEmitRequest($endOfHeader); |
| 48 | + $request = $this->parseRequest((string)\substr($this->buffer, 0, $endOfHeader)); |
48 | 49 | } catch (Exception $exception) { |
49 | 50 | $this->emit('error', array($exception)); |
| 51 | + $this->removeAllListeners(); |
| 52 | + return; |
50 | 53 | } |
| 54 | + |
| 55 | + $bodyBuffer = isset($this->buffer[$endOfHeader + 4]) ? \substr($this->buffer, $endOfHeader + 4) : ''; |
| 56 | + $this->emit('headers', array($request, $bodyBuffer)); |
51 | 57 | $this->removeAllListeners(); |
52 | 58 | } |
53 | 59 | } |
54 | 60 |
|
55 | | - private function parseAndEmitRequest($endOfHeader) |
56 | | - { |
57 | | - $request = $this->parseRequest((string)\substr($this->buffer, 0, $endOfHeader)); |
58 | | - $bodyBuffer = isset($this->buffer[$endOfHeader + 4]) ? \substr($this->buffer, $endOfHeader + 4) : ''; |
59 | | - $this->emit('headers', array($request, $bodyBuffer)); |
60 | | - } |
61 | | - |
| 61 | + /** |
| 62 | + * @param string $headers buffer string containing request headers only |
| 63 | + * @throws \InvalidArgumentException |
| 64 | + * @return ServerRequestInterface |
| 65 | + */ |
62 | 66 | private function parseRequest($headers) |
63 | 67 | { |
64 | 68 | // additional, stricter safe-guard for request line |
|
0 commit comments