diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2017-10-20 09:15:22 +0200 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2017-10-20 09:15:22 +0200 |
commit | 03099824a883b50141652f160eb2aaa3790ad6a3 (patch) | |
tree | b3e92e1d8b933999533f53cd1440475e1aa328c8 | |
parent | 29c55245686d1ad03aa3bdd995a233cf66395d6c (diff) | |
download | Fastcgi-03099824a883b50141652f160eb2aaa3790ad6a3.zip Fastcgi-03099824a883b50141652f160eb2aaa3790ad6a3.tar.gz Fastcgi-03099824a883b50141652f160eb2aaa3790ad6a3.tar.bz2 |
feat(Responder) Handle unknown server status.
Throws a `Exception\UnknownStatus` when the server returns an unknown
status.
-rw-r--r-- | Responder.php | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/Responder.php b/Responder.php index fc4f43b..749bff9 100644 --- a/Responder.php +++ b/Responder.php @@ -176,6 +176,7 @@ class Responder extends Connection * @throws \Hoa\Fastcgi\Exception\CannotMultiplex * @throws \Hoa\Fastcgi\Exception\Overloaded * @throws \Hoa\Fastcgi\Exception\UnknownRole + * @throws \Hoa\Fastcgi\Exception\UnknownStatus */ public function send(array $headers, $content = null) { @@ -234,12 +235,14 @@ class Responder extends Connection $client->disconnect(); - switch (ord($handle[parent::HEADER_CONTENT][4])) { + $status = ord($handle[parent::HEADER_CONTENT][4]); + + switch ($status) { case self::STATUS_CANNOT_MULTIPLEX: throw new Exception\CannotMultiplex( 'Application %s that you are trying to reach does not ' . 'support multiplexing.', - 0, + 1, $this->getClient()->getSocket()->__toString() ); @@ -248,7 +251,7 @@ class Responder extends Connection case self::STATUS_OVERLOADED: throw new Exception\Overloaded( 'Application %s is too busy and rejects your request.', - 1, + 2, $this->getClient()->getSocket()->__toString() ); @@ -257,17 +260,25 @@ class Responder extends Connection case self::STATUS_UNKNOWN_ROLE: throw new Exception\UnknownRole( 'Server for the application %s returns an unknown role.', - 2, + 3, $this->getClient()->getSocket()->__toString() ); break; - } - /** - * default: // self::STATUS_COMPLETE - * break; - */ + case self::STATUS_COMPLETE: + break; + + default: + throw new Exception\UnknownStatus( + 'Server for the application %s returns an unknown status: %d.', + 4, + [ + $this->getClient()->getSocket()->__toString(), + $status + ] + ); + } $pos = strpos($response, "\r\n\r\n"); $headers = substr($response, 0, $pos); |