Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature | Added isJson and isXML functions to Response class #455

Open
wants to merge 4 commits into
base: v3
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,26 @@ public function header(string $header): string|array|null
return $this->headers()->get($header);
}

/**
* Determine if the response is in JSON format.
*
* @return bool
*/
public function isJson(): bool
{
return str_contains($this->header('Content-Type'), 'json');
}

/**
* Determine if the response is in XML format.
*
* @return bool
*/
public function isXml(): bool
{
return str_contains($this->header('Content-Type'), 'xml');
}

/**
* Create a temporary resource for the stream.
*
Expand Down