diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2014-01-07 15:20:22 (GMT) |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2014-01-07 15:41:22 (GMT) |
commit | e636dd31dca8701914dda591c2bab76bc7fcab84 (patch) | |
tree | 47b9bacf459a4b00ea4324a4ecfc86a1f42ec83f | |
parent | 05c26255a8e6cdcb258e66b64b2b70779f819cca (diff) | |
download | iRony-e636dd31dca8701914dda591c2bab76bc7fcab84.tar.gz |
Overload ServiceUnavailable exception class to send a Retry-After header (#2745)
-rw-r--r-- | lib/Kolab/DAV/Auth/HTTPBasic.php | 2 | ||||
-rw-r--r-- | lib/Kolab/DAV/Auth/ServiceUnavailable.php | 59 |
2 files changed, 60 insertions, 1 deletions
diff --git a/lib/Kolab/DAV/Auth/HTTPBasic.php b/lib/Kolab/DAV/Auth/HTTPBasic.php index 4bf2aa8..e9dc2b9 100644 --- a/lib/Kolab/DAV/Auth/HTTPBasic.php +++ b/lib/Kolab/DAV/Auth/HTTPBasic.php @@ -94,7 +94,7 @@ class HTTPBasic extends DAV\Auth\Backend\AbstractBasic // LDAP server failure... send 503 error if ($auth['kolab_ldap_error']) { - throw new DAV\Exception\ServiceUnavailable('The service is temporarily unavailable (LDAP failure)'); + throw new ServiceUnavailable('The service is temporarily unavailable (LDAP failure)'); } } diff --git a/lib/Kolab/DAV/Auth/ServiceUnavailable.php b/lib/Kolab/DAV/Auth/ServiceUnavailable.php new file mode 100644 index 0000000..f0a1f25 --- /dev/null +++ b/lib/Kolab/DAV/Auth/ServiceUnavailable.php @@ -0,0 +1,59 @@ +<?php + +/** + * 503 Service Unavailable exception + * + * @author Thomas Bruederli <bruederli@kolabsys.com> + * + * Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace Kolab\DAV\Auth; + +use Sabre\DAV; + +/** + * 503 Service Unavailable + * + * This exception is thrown in case the service + * is currently not available (e.g. down for maintenance). + */ +class ServiceUnavailable extends DAV\Exception\ServiceUnavailable +{ + private $retry_after = 600; + + function __construct($message, $retry = 600) + { + parent::__construct($message); + + $this->retry_after = $retry; + } + + /** + * This method allows the exception to return any extra HTTP response headers. + * + * The headers must be returned as an array. + * + * @param Server $server + * @return array + */ + public function getHTTPHeaders(DAV\Server $server) + { + return array( + 'Retry-After' => $this->retry_after, + ); + } +} |