@@ -43,6 +43,9 @@ class Http
43
43
*/
44
44
public static function input ($ recv_buffer , TcpConnection $ connection )
45
45
{
46
+ if (isset (static ::$ _cache [$ recv_buffer ]['input ' ])) {
47
+ return static ::$ _cache [$ recv_buffer ]['input ' ];
48
+ }
46
49
$ recv_len = \strlen ($ recv_buffer );
47
50
$ crlf_post = \strpos ($ recv_buffer , "\r\n\r\n" );
48
51
if (!$ crlf_post ) {
@@ -61,13 +64,16 @@ public static function input($recv_buffer, TcpConnection $connection)
61
64
}
62
65
63
66
if ($ method === 'GET ' || $ method === 'OPTIONS ' || $ method === 'HEAD ' ) {
67
+ static ::$ _cache [$ recv_buffer ]['input ' ] = $ recv_len ;
64
68
return $ recv_len ;
65
69
}
66
70
67
71
$ match = array ();
68
72
if (\preg_match ("/ \r\nContent-Length: ?(\d+)/i " , $ recv_buffer , $ match )) {
69
73
$ content_length = isset ($ match [1 ]) ? $ match [1 ] : 0 ;
70
- return $ content_length + $ crlf_post + 4 ;
74
+ $ total_length = $ content_length + $ crlf_post + 4 ;
75
+ static ::$ _cache [$ recv_buffer ]['input ' ] = $ total_length ;
76
+ return $ total_length ;
71
77
}
72
78
73
79
return $ method === 'DELETE ' ? $ recv_len : 0 ;
@@ -82,9 +88,9 @@ public static function input($recv_buffer, TcpConnection $connection)
82
88
*/
83
89
public static function decode ($ recv_buffer , TcpConnection $ connection )
84
90
{
85
- if (isset (static ::$ _cache [$ recv_buffer ])) {
91
+ if (isset (static ::$ _cache [$ recv_buffer ][ ' decode ' ] )) {
86
92
HttpCache::reset ();
87
- $ cache = static ::$ _cache [$ recv_buffer ];
93
+ $ cache = static ::$ _cache [$ recv_buffer ][ ' decode ' ] ;
88
94
//$cache['server']['REQUEST_TIME_FLOAT'] = \microtime(true);
89
95
//$cache['server']['REQUEST_TIME'] = (int)$cache['server']['REQUEST_TIME_FLOAT'];
90
96
$ _SERVER = $ cache ['server ' ];
@@ -93,7 +99,7 @@ public static function decode($recv_buffer, TcpConnection $connection)
93
99
$ _COOKIE = $ cache ['cookie ' ];
94
100
$ _REQUEST = $ cache ['request ' ];
95
101
$ GLOBALS ['HTTP_RAW_POST_DATA ' ] = $ GLOBALS ['HTTP_RAW_REQUEST_DATA ' ] = '' ;
96
- return static ::$ _cache [$ recv_buffer ];
102
+ return static ::$ _cache [$ recv_buffer ][ ' decode ' ] ;
97
103
}
98
104
// Init.
99
105
$ _POST = $ _GET = $ _COOKIE = $ _REQUEST = $ _SESSION = $ _FILES = array ();
@@ -230,7 +236,7 @@ public static function decode($recv_buffer, TcpConnection $connection)
230
236
$ _SERVER ['REMOTE_PORT ' ] = $ connection ->getRemotePort ();
231
237
$ ret = array ('get ' => $ _GET , 'post ' => $ _POST , 'cookie ' => $ _COOKIE , 'server ' => $ _SERVER , 'files ' => $ _FILES , 'request ' =>$ _REQUEST );
232
238
if ($ _SERVER ['REQUEST_METHOD ' ] === 'GET ' ) {
233
- static ::$ _cache [$ recv_buffer ] = $ ret ;
239
+ static ::$ _cache [$ recv_buffer ][ ' decode ' ] = $ ret ;
234
240
if (\count (static ::$ _cache ) > 256 ) {
235
241
unset(static ::$ _cache [key (static ::$ _cache )]);
236
242
}
0 commit comments