Skip to content

Commit 6220030

Browse files
committed
set content-type application/json in contruct response
1 parent e080bde commit 6220030

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Response.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
use PhpRestfulApiResponse\Contracts\PhpRestfulApiResponse;
1717
use Zend\Diactoros\MessageTrait;
1818
use InvalidArgumentException;
19+
use Zend\Diactoros\Response\InjectContentTypeTrait;
1920
use Zend\Diactoros\Response\JsonResponse;
2021

2122
class Response implements PhpRestfulApiResponse
2223
{
23-
use MessageTrait;
24+
use MessageTrait, InjectContentTypeTrait;
2425

2526
const MIN_STATUS_CODE_VALUE = 100;
2627
const MAX_STATUS_CODE_VALUE = 599;
@@ -131,6 +132,7 @@ public function __construct($body = 'php://memory', int $status = 200, $errorCod
131132
$this->setStatusCode($status);
132133
$this->setErrorCode($errorCode);
133134
$this->stream = $this->getStream($body, 'wb+');
135+
$headers = $this->injectContentType('application/json', $headers);
134136
$this->setHeaders($headers);
135137
}
136138

@@ -178,7 +180,6 @@ public function withArray($data, $code = 200, array $headers = [])
178180
$new = clone $this;
179181
$new->setStatusCode($code);
180182
$new->getBody()->write($this->jsonEncode($data));
181-
$new = $new->withHeader('Content-Type', 'application/json');
182183
$new->headers = array_merge($new->headers, $headers);
183184
return $new;
184185
}
@@ -262,7 +263,6 @@ public function withError($message, int $statusCode, $errorCode = null, array $h
262263
]
263264
)
264265
);
265-
$new = $new->withHeader('Content-Type', 'application/json');
266266
$new->headers = array_merge($new->headers, $headers);
267267
return $new;
268268
}

0 commit comments

Comments
 (0)