diff --git a/src/future/http/status/HTTPFutureHTTPResponseStatus.php b/src/future/http/status/HTTPFutureHTTPResponseStatus.php index 466030b..469f9a0 100644 --- a/src/future/http/status/HTTPFutureHTTPResponseStatus.php +++ b/src/future/http/status/HTTPFutureHTTPResponseStatus.php @@ -1,62 +1,67 @@ 512) { $excerpt = substr($body, 0, 512).'...'; } else { $excerpt = $body; } $content_type = BaseHTTPFuture::getHeader($headers, 'Content-Type'); $match = null; if (preg_match('/;\s*charset=([^;]+)/', $content_type, $match)) { $encoding = trim($match[1], "\"'"); try { $excerpt = phutil_utf8_convert($excerpt, 'UTF-8', $encoding); } catch (Exception $ex) {} } $this->excerpt = phutil_utf8ize($excerpt); $this->expect = $expect; parent::__construct($status_code); } protected function getErrorCodeType($code) { return 'HTTP'; } public function isError() { if ($this->expect === null) { - return ($this->getStatusCode() < 200) || ($this->getStatusCode() > 299); + return ($this->getStatusCode() < 200) || ($this->getStatusCode() > 299); } return !in_array($this->getStatusCode(), $this->expect, true); } + public function isRedirect() { + $code = $this->getStatusCode(); + return ($code >= 300 && $code < 400); + } + public function isTimeout() { return false; } protected function getErrorCodeDescription($code) { static $map = array( 404 => 'Not Found', 500 => 'Internal Server Error', ); return idx($map, $code)."\n".$this->excerpt."\n"; } } diff --git a/src/future/http/status/HTTPFutureResponseStatus.php b/src/future/http/status/HTTPFutureResponseStatus.php index c704e4a..5bf68f0 100644 --- a/src/future/http/status/HTTPFutureResponseStatus.php +++ b/src/future/http/status/HTTPFutureResponseStatus.php @@ -1,39 +1,43 @@ statusCode = $status_code; $this->uri = (string)$uri; $type = $this->getErrorCodeType($status_code); $description = $this->getErrorCodeDescription($status_code); $uri_info = ''; if ($this->uri) { $uri_info = ' ('.$this->uri.')'; } $message = rtrim("[{$type}/{$status_code}]{$uri_info} {$description}"); parent::__construct($message); } final public function getStatusCode() { return $this->statusCode; } final public function getURI() { return $this->uri; } abstract public function isError(); abstract public function isTimeout(); + public function isRedirect() { + return false; + } + abstract protected function getErrorCodeType($code); abstract protected function getErrorCodeDescription($code); }