mirror of
https://github.com/friendica/friendica
synced 2025-04-23 19:10:13 +00:00
Fixing Response
This commit is contained in:
parent
ae24bf8d54
commit
6a9fff5100
11 changed files with 41 additions and 12 deletions
|
@ -199,10 +199,10 @@ class ApiResponse extends Response
|
|||
|
||||
switch ($format) {
|
||||
case 'xml':
|
||||
$this->setHeader('Content-Type: text/xml');
|
||||
$this->setType(static::TYPE_XML);
|
||||
break;
|
||||
case 'json':
|
||||
$this->setHeader('Content-Type: application/json');
|
||||
$this->setType(static::TYPE_JSON);
|
||||
if (!empty($return)) {
|
||||
$json = json_encode(end($return));
|
||||
if (!empty($_GET['callback'])) {
|
||||
|
@ -212,10 +212,10 @@ class ApiResponse extends Response
|
|||
}
|
||||
break;
|
||||
case 'rss':
|
||||
$this->setHeader('Content-Type: application/rss+xml');
|
||||
$this->setType(static::TYPE_RSS);
|
||||
break;
|
||||
case 'atom':
|
||||
$this->setHeader('Content-Type: application/atom+xml');
|
||||
$this->setType(static::TYPE_ATOM);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class Response implements ICanCreateResponses
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = ICanCreateResponses::TYPE_HTML;
|
||||
protected $type = self::TYPE_HTML;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -68,7 +68,7 @@ class Response implements ICanCreateResponses
|
|||
*/
|
||||
public function setType(string $type, ?string $content_type = null): void
|
||||
{
|
||||
if (!in_array($type, ICanCreateResponses::ALLOWED_TYPES)) {
|
||||
if (!in_array($type, static::ALLOWED_TYPES)) {
|
||||
throw new InternalServerErrorException('wrong type');
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,14 @@ class Response implements ICanCreateResponses
|
|||
case static::TYPE_XML:
|
||||
$content_type = $content_type ?? 'text/xml';
|
||||
break;
|
||||
case static::TYPE_RSS:
|
||||
$content_type = $content_type ?? 'application/rss+xml';
|
||||
break;
|
||||
case static::TYPE_ATOM:
|
||||
$content_type = $content_type ?? 'application/atom+xml';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$this->setHeader($content_type, 'Content-type');
|
||||
|
||||
$this->type = $type;
|
||||
|
@ -101,7 +106,7 @@ class Response implements ICanCreateResponses
|
|||
public function generate(): ResponseInterface
|
||||
{
|
||||
// Setting the response type as an X-header for direct usage
|
||||
$this->headers['X-RESPONSE-TYPE'] = $this->type;
|
||||
$this->headers[static::X_HEADER] = $this->type;
|
||||
|
||||
return new \GuzzleHttp\Psr7\Response(200, $this->headers, $this->content);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue