Skip to content

Commit

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


/**
* Returns decoded content of HTTP request body.
*/
public function getBody(): mixed
{
$type = $this->getHeader('Content-Type');
switch ($type) {
case 'application/json':
return json_decode($this->getRawBody());
case 'application/x-www-form-urlencoded':
return $_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 9f8486f

Please sign in to comment.