Skip to content

Commit

Permalink
Request::getDecodedBody() WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 5, 2024
1 parent 11b260d commit a3719ca
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 @@ -266,6 +266,20 @@ public function getRawBody(): ?string
}


/**
* Returns decoded content of HTTP request body.
*/
public function getDecodedBody(): 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 a3719ca

Please sign in to comment.