aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-10-20 09:28:38 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-10-20 09:28:38 +0200
commit493df21c2de61a82d6ed022c624524569539cc29 (patch)
treee13e8504415714166248a9b0dd4c97ab3b4f77b9
parent6458f636ceba79121c3e426922eed0a0f5a16b48 (diff)
downloadFastcgi-493df21c2de61a82d6ed022c624524569539cc29.zip
Fastcgi-493df21c2de61a82d6ed022c624524569539cc29.tar.gz
Fastcgi-493df21c2de61a82d6ed022c624524569539cc29.tar.bz2
feat(Responder) Decorrelate error from output.
The response output and error were read in the same place, accessible through `getResponseContent`. Now, the response output is still accessible through `getResponseContent` but the response error is now accessible through `getResponseError` if any.
-rw-r--r--Responder.php59
1 files changed, 39 insertions, 20 deletions
diff --git a/Responder.php b/Responder.php
index e1c903f..93238a2 100644
--- a/Responder.php
+++ b/Responder.php
@@ -135,21 +135,28 @@ class Responder extends Connection
*
* @var \Hoa\Socket\Client
*/
- protected $_client = null;
+ protected $_client = null;
/**
- * Response: content.
+ * Response's output.
*
* @var string
*/
- protected $_content = null;
+ protected $_responseOutput = null;
/**
- * Response: headers.
+ * Response's error.
+ *
+ * @var string
+ */
+ protected $_responseError = null;
+
+ /**
+ * Response's headers.
*
* @var array
*/
- protected $_headers = [];
+ protected $_responseHeaders = [];
@@ -178,18 +185,20 @@ class Responder extends Connection
* @throws \Hoa\Fastcgi\Exception\UnknownRole
* @throws \Hoa\Fastcgi\Exception\UnknownStatus
*/
- public function send(array $headers, $content = null, &$stderr = '')
+ public function send(array $headers, $content = null)
{
- $this->_content = null;
- $this->_headers = [];
+ $this->_responseOutput = null;
+ $this->_responseError = null;
+ $this->_responseHeaders = [];
$client = $this->getClient();
$client->connect();
$client->setStreamBlocking(true);
- $parameters = null;
- $response = null;
- $request = $this->pack(
+ $parameters = null;
+ $responseOutput = null;
+
+ $request = $this->pack(
self::REQUEST_BEGIN,
// ┌───────────────────┐
// │ “I'm a responder” │
@@ -228,11 +237,11 @@ class Responder extends Connection
}
if (self::STREAM_STDOUT === $handle[parent::HEADER_TYPE]) {
- $response .= $handle[parent::HEADER_CONTENT];
+ $responseOutput .= $handle[parent::HEADER_CONTENT];
}
if (self::STREAM_STDERR === $handle[parent::HEADER_TYPE]) {
- $stderr .= $handle[parent::HEADER_CONTENT];
+ $this->_responseError .= $handle[parent::HEADER_CONTENT];
}
} while (self::REQUEST_END !== $handle[parent::HEADER_TYPE]);
@@ -283,26 +292,36 @@ class Responder extends Connection
);
}
- $pos = strpos($response, "\r\n\r\n");
- $headers = substr($response, 0, $pos);
+ $pos = strpos($responseOutput, "\r\n\r\n");
+ $headers = substr($responseOutput, 0, $pos);
foreach (explode("\r\n", $headers) as $header) {
$semicolon = strpos($header, ':');
- $this->_headers[strtolower(trim(substr($header, 0, $semicolon)))]
+ $this->_responseHeaders[strtolower(trim(substr($header, 0, $semicolon)))]
= trim(substr($header, $semicolon + 1));
}
- return $this->_content = substr($response, $pos + 4);
+ return $this->_responseOutput = substr($responseOutput, $pos + 4);
}
/**
* Get response content.
*
- * @return string
+ * @return ?string
*/
public function getResponseContent()
{
- return $this->_content;
+ return $this->_responseOutput;
+ }
+
+ /**
+ * Get response error if any.
+ *
+ * @return ?string
+ */
+ public function getResponseError()
+ {
+ return $this->_responseError;
}
/**
@@ -312,7 +331,7 @@ class Responder extends Connection
*/
public function getResponseHeaders()
{
- return $this->_headers;
+ return $this->_responseHeaders;
}
/**