Skip to content

Commit

Permalink
Request::getDecodedBody() WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 29, 2024
1 parent 343a63a commit 1b8b368
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 @@ -268,6 +268,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 1b8b368

Please sign in to comment.