File tree Expand file tree Collapse file tree 2 files changed +39
-5
lines changed Expand file tree Collapse file tree 2 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -17,21 +17,28 @@ class RequestHeaderParser extends EventEmitter
17
17
18
18
public function feed ($ data )
19
19
{
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 ) {
21
31
$ this ->emit ('error ' , array (new \OverflowException ("Maximum header size of {$ this ->maxSize } exceeded. " ), $ this ));
22
32
$ this ->removeAllListeners ();
23
33
return ;
24
34
}
25
35
26
- $ this ->buffer .= $ data ;
27
-
28
- if (false !== strpos ($ this ->buffer , "\r\n\r\n" )) {
36
+ if (false !== $ endOfHeader ) {
29
37
try {
30
38
$ this ->parseAndEmitRequest ();
31
39
} catch (Exception $ exception ) {
32
40
$ this ->emit ('error ' , [$ exception ]);
33
41
}
34
-
35
42
$ this ->removeAllListeners ();
36
43
}
37
44
}
Original file line number Diff line number Diff line change @@ -121,6 +121,33 @@ public function testHeaderOverflowShouldEmitError()
121
121
$ this ->assertSame (0 , count ($ parser ->listeners ('error ' )));
122
122
}
123
123
124
+ public function testHeaderOverflowShouldNotEmitErrorWhenDataExceedsMaxHeaderSize ()
125
+ {
126
+ $ request = null ;
127
+ $ bodyBuffer = null ;
128
+
129
+ $ parser = new RequestHeaderParser ();
130
+ $ parser ->on ('headers ' , function ($ parsedRequest , $ parsedBodyBuffer ) use (&$ request , &$ bodyBuffer ) {
131
+ $ request = $ parsedRequest ;
132
+ $ bodyBuffer = $ parsedBodyBuffer ;
133
+ });
134
+
135
+ $ data = $ this ->createAdvancedPostRequest ();
136
+ $ body = str_repeat ('A ' , 4097 - strlen ($ data ));
137
+ $ data .= $ body ;
138
+
139
+ $ parser ->feed ($ data );
140
+
141
+ $ headers = array (
142
+ 'Host ' => 'example.com:80 ' ,
143
+ 'User-Agent ' => 'react/alpha ' ,
144
+ 'Connection ' => 'close ' ,
145
+ );
146
+ $ this ->assertSame ($ headers , $ request ->getHeaders ());
147
+
148
+ $ this ->assertSame ($ body , $ bodyBuffer );
149
+ }
150
+
124
151
public function testGuzzleRequestParseException ()
125
152
{
126
153
$ error = null ;
You can’t perform that action at this time.
0 commit comments