File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -17,21 +17,28 @@ class RequestHeaderParser extends EventEmitter
1717
1818 public function feed ($ data )
1919 {
20- if (strlen ($ this ->buffer ) + strlen ($ data ) > $ this ->maxSize ) {
20+ $ this ->buffer .= $ data ;
21+
22+ $ endOfHeader = strpos ($ this ->buffer , "\r\n\r\n" );
23+
24+ if (false !== $ endOfHeader ) {
25+ $ currentHeaderSize = $ endOfHeader ;
26+ } else {
27+ $ currentHeaderSize = strlen ($ this ->buffer );
28+ }
29+
30+ if ($ currentHeaderSize > $ this ->maxSize ) {
2131 $ this ->emit ('error ' , array (new \OverflowException ("Maximum header size of {$ this ->maxSize } exceeded. " ), $ this ));
2232 $ this ->removeAllListeners ();
2333 return ;
2434 }
2535
26- $ this ->buffer .= $ data ;
27-
28- if (false !== strpos ($ this ->buffer , "\r\n\r\n" )) {
36+ if (false !== $ endOfHeader ) {
2937 try {
3038 $ this ->parseAndEmitRequest ();
3139 } catch (Exception $ exception ) {
3240 $ this ->emit ('error ' , [$ exception ]);
3341 }
34-
3542 $ this ->removeAllListeners ();
3643 }
3744 }
Original file line number Diff line number Diff line change @@ -41,6 +41,9 @@ public function __construct(SocketServerInterface $io)
4141 $ conn ->emit ('resume ' );
4242 });
4343 });
44+ $ parser ->on ('error ' , function ($ exception ) {
45+ $ this ->emit ('error ' , [$ exception ]);
46+ });
4447
4548 $ conn ->on ('data ' , array ($ parser , 'feed ' ));
4649 });
You can’t perform that action at this time.
0 commit comments