summaryrefslogtreecommitdiff
path: root/src/Middleware/SendResponseHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Middleware/SendResponseHandler.php')
-rw-r--r--src/Middleware/SendResponseHandler.php30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/Middleware/SendResponseHandler.php b/src/Middleware/SendResponseHandler.php
index 06406fe0..34e70a87 100644
--- a/src/Middleware/SendResponseHandler.php
+++ b/src/Middleware/SendResponseHandler.php
@@ -24,8 +24,8 @@ class SendResponseHandler implements MiddlewareInterface
): ResponseInterface {
$response = $handler->handle($request);
- if (!headers_sent()) {
- header(sprintf(
+ if (!$this->headersSent()) {
+ $this->sendHeader(sprintf(
'HTTP/%s %s %s',
$response->getProtocolVersion(),
$response->getStatusCode(),
@@ -34,7 +34,7 @@ class SendResponseHandler implements MiddlewareInterface
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
- header($name . ': ' . $value, false);
+ $this->sendHeader($name . ': ' . $value, false);
}
}
}
@@ -42,4 +42,28 @@ class SendResponseHandler implements MiddlewareInterface
echo $response->getBody();
return $response;
}
+
+ /**
+ * Checks if headers have been sent
+ *
+ * @return bool
+ * @codeCoverageIgnore
+ */
+ protected function headersSent()
+ {
+ return headers_sent();
+ }
+
+ /**
+ * Send a raw HTTP header
+ *
+ * @param string $content
+ * @param bool $replace
+ * @param int $code
+ * @codeCoverageIgnore
+ */
+ protected function sendHeader($content, $replace = true, $code = null)
+ {
+ header($content, $replace, $code);
+ }
}