Skip to content

Commit

Permalink
Request::getBody() WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 11, 2023
1 parent 1c931e1 commit f09b0a0
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 @@ -270,6 +270,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 f09b0a0

Please sign in to comment.