Skip to content

Commit 8b0951f

Browse files
committed
Fix content bug
1 parent 4ec23c7 commit 8b0951f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/ContentType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ final class ContentType
1818
public const HTML = 'text/html';
1919
public const TEXT = 'text/plain';
2020
public const JSON = 'application/json';
21-
public const XML = 'application/xml';
21+
public const XML = 'application/xml';
2222
public const FORM = 'application/x-www-form-urlencoded';
23+
public const FORM_DATA = 'multipart/form-data';
2324

2425
// Content types mapping
2526
public const TYPES = [

src/Request.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Swoft\Http\Message\Helper\HttpHelper;
1212
use Swoft\Http\Message\Stream\Stream;
1313
use Swoft\Http\Message\Uri\Uri;
14+
use Swoft\Stdlib\Helper\Str;
1415
use Swoole\Http\Request as CoRequest;
1516

1617
/**
@@ -311,9 +312,18 @@ public function getParsedBody()
311312
return $this->parsedBody;
312313
}
313314

314-
315315
$parsedBody = $this->coRequest->post ?? [];
316316

317+
$needles = [
318+
ContentType::FORM,
319+
ContentType::FORM_DATA,
320+
];
321+
$contentType = $this->getHeaderLine(ContentType::KEY);
322+
if (Str::contains($contentType, $needles)) {
323+
$this->parsedBody = $parsedBody;
324+
return $parsedBody;
325+
}
326+
317327
// Parse body
318328
if (!$parsedBody && !$this->isGet()) {
319329
$rawBody = $this->getRawBody();
@@ -323,7 +333,6 @@ public function getParsedBody()
323333
}
324334

325335
$this->parsedBody = $parsedBody;
326-
327336
return $this->parsedBody;
328337
}
329338

0 commit comments

Comments
 (0)