Skip to content

Commit

Permalink
Request::getBody() WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 14, 2023
1 parent b2a5951 commit a20fb8f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ public function getRawBody(): ?string
}


/**
* Returns decoded content of HTTP request body.
*/
public function getBody(): mixed
{
$type = $this->getHeader('Content-Type');
return match ($type) {
'application/json' => json_decode($this->getRawBody()),
'application/x-www-form-urlencoded' => $_POST,
default => throw new \Exception("Unsupported content type: $type"),
};
}


/**
* Returns basic HTTP authentication credentials.
* @return array{string, string}|null
Expand Down

0 comments on commit a20fb8f

Please sign in to comment.