diff --git a/Protocols/Http.php b/Protocols/Http.php index 30c3ba9..fef6451 100644 --- a/Protocols/Http.php +++ b/Protocols/Http.php @@ -65,7 +65,7 @@ public static function input($recv_buffer, TcpConnection $connection) */ protected static function getRequestSize($header, $method) { - if($method=='GET') { + if($method === 'GET' || $method === 'OPTIONS' || $method === 'HEAD') { return strlen($header) + 4; } $match = array(); @@ -108,6 +108,7 @@ public static function decode($recv_buffer, TcpConnection $connection) 'HTTP_CONNECTION' => '', 'REMOTE_ADDR' => '', 'REMOTE_PORT' => '0', + 'REQUEST_TIME' => time() ); // Parse headers. @@ -158,21 +159,30 @@ public static function decode($recv_buffer, TcpConnection $connection) // Parse $_POST. if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] === 'multipart/form-data') { - self::parseUploadFiles($http_body, $http_post_boundary); + if (isset($_SERVER['CONTENT_TYPE'])) { + switch ($_SERVER['CONTENT_TYPE']) { + case 'multipart/form-data': + self::parseUploadFiles($http_body, $http_post_boundary); + break; + case 'application/x-www-form-urlencoded': + parse_str($http_body, $_POST); + break; + default: + // $GLOBALS['HTTP_RAW_POST_DATA'] + $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $GLOBALS['HTTP_RAW_POST_DATA'] = $http_body; + } } else { - parse_str($http_body, $_POST); // $GLOBALS['HTTP_RAW_POST_DATA'] $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $GLOBALS['HTTP_RAW_POST_DATA'] = $http_body; } } if ($_SERVER['REQUEST_METHOD'] === 'PUT') { - $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $http_body; + $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $http_body; } if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { - $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $http_body; + $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $http_body; } // QUERY_STRING @@ -437,16 +447,19 @@ protected static function parseUploadFiles($http_body, $http_post_boundary) list($boundary_header_buffer, $boundary_value) = explode("\r\n\r\n", $boundary_data_buffer, 2); // Remove \r\n from the end of buffer. $boundary_value = substr($boundary_value, 0, -2); + $key = -1; foreach (explode("\r\n", $boundary_header_buffer) as $item) { list($header_key, $header_value) = explode(": ", $item); $header_key = strtolower($header_key); switch ($header_key) { case "content-disposition": + $key ++; // Is file data. - if (preg_match('/name=".*?"; filename="(.*?)"$/', $header_value, $match)) { + if (preg_match('/name="(.*?)"; filename="(.*?)"$/', $header_value, $match)) { // Parse $_FILES. - $_FILES[] = array( - 'file_name' => $match[1], + $_FILES[$key] = array( + 'name' => $match[1], + 'file_name' => $match[2], 'file_data' => $boundary_value, 'file_size' => strlen($boundary_value), ); @@ -459,6 +472,10 @@ protected static function parseUploadFiles($http_body, $http_post_boundary) } } break; + case "content-type": + // add file_type + $_FILES[$key]['file_type'] = trim($header_value); + break; } } } @@ -553,7 +570,7 @@ class HttpCache public static function init() { self::$sessionName = ini_get('session.name'); - self::$sessionPath = session_save_path(); + self::$sessionPath = @session_save_path(); if (!self::$sessionPath || strpos(self::$sessionPath, 'tcp://') === 0) { self::$sessionPath = sys_get_temp_dir(); } diff --git a/Protocols/Ws.php b/Protocols/Ws.php index da1451f..020014e 100644 --- a/Protocols/Ws.php +++ b/Protocols/Ws.php @@ -289,7 +289,7 @@ public static function encode($payload, $connection) */ public static function decode($bytes, $connection) { - $masked = $bytes[1] >> 7; + $masked = ord($bytes[1]) >> 7; $data_length = $masked ? ord($bytes[1]) & 127 : ord($bytes[1]); $decoded_data = ''; if ($masked === true) {