Mercurial > SimpleWebPresenter
diff common-functions.inc @ 88:7a9c45b53866
Add possibility to validate using validator.w3.org
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 17 Oct 2012 20:43:07 +0200 |
| parents | ff5fc61aa5ea |
| children | aafc23919e79 |
line wrap: on
line diff
--- a/common-functions.inc Mon Oct 15 18:32:56 2012 +0200 +++ b/common-functions.inc Wed Oct 17 20:43:07 2012 +0200 @@ -12,6 +12,24 @@ $cache->includeOnce('StatusCodes.inc', $baseDir); /// @endcond +class RequestException extends RuntimeException +{ + private $_info; + + function __construct($info) + { + $this->_info = $info; + if (array_key_exists('error', $info)) { + parent::__construct($info['error']); + } + } + + function info() + { + return $this->_info; + } +} + /** * Generates a representation for an array of key => value pairs * @@ -194,9 +212,14 @@ * @param $url the url to query * @return an associative array of all headers returned */ -function getHeaders($url) +function getHeaders($url, $timeout = 1) { - $response = http_head($url, array("timeout" => 1), $info); + $response = @http_head($url, array("timeout" => $timeout), $info); + + if (array_key_exists('error', $info) && $info['error']) { + throw new RequestException($info); + } + $headers = array(); $response = trim($response); $str = explode("\n", $response);
