summaryrefslogtreecommitdiff
path: root/src/Middleware/SendResponseHandler.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-08-11 23:46:28 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-08-19 13:59:39 +0200
commitf3b3b6683ca90b70ec4d4daae002dc0caac9ebdd (patch)
treec550252995a46763d8c540c9bd7f41e4b1c4f246 /src/Middleware/SendResponseHandler.php
parentf3f05f6cc4bef3338dbfb6eb340da4fb1c5ba1e1 (diff)
Added middleware tests
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);
+ }
}