浏览代码

parser fix test

ljoaquim 3 周之前
父节点
当前提交
6b14992590
共有 1 个文件被更改,包括 17 次插入3 次删除
  1. 17 3
      libs/MultipartFormDataParser.php

+ 17 - 3
libs/MultipartFormDataParser.php

@@ -17,7 +17,21 @@ class MultipartFormDataParser
         if ($boundary === '') {
             throw new \RuntimeException('Missing multipart boundary');
         }
-        $rawBody = (string)$request->getBody();
+
+        $rawBody = '';
+        $stream = $request->getBody();
+        if (is_object($stream) && method_exists($stream, 'getContents')) {
+            $rawBody = (string)$stream->getContents();
+            if (method_exists($stream, 'rewind')) {
+                try {
+                    $stream->rewind();
+                } catch (\Throwable $e) {
+                }
+            }
+        } else {
+            $rawBody = (string)$stream;
+        }
+
         if ($rawBody === '') {
             $rawBody = (string)file_get_contents('php://input');
         }
@@ -29,8 +43,8 @@ class MultipartFormDataParser
         $files = [];
 
         foreach ($parts as $part) {
-            $part = ltrim($part, "\r\n");
-            $part = rtrim($part, "\r\n");
+            $part = ltrim($part, "\r\n\n");
+            $part = rtrim($part, "\r\n\n");
 
             if ($part === '' || $part === '--') {
                 continue;