X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fhttpclient.php;h=819a5e6e0799140646ac01aa8c76cd6e0b058608;hb=586fb5a5175d7a10f5f78dd026434e48202e5451;hp=1e399bd83e9ead32b464cefaa7774ff7eef28c28;hpb=9fa18fa3669c6d15109b239f92f4166e4f1365f0;p=quix0rs-gnu-social.git diff --git a/lib/httpclient.php b/lib/httpclient.php index 1e399bd83e..819a5e6e07 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -116,7 +116,18 @@ class HTTPClient extends HTTP_Request2 function __construct($url=null, $method=self::METHOD_GET, $config=array()) { - $this->config['connect_timeout'] = common_config('http', 'connect_timeout') ?: $this->config['connect_timeout']; + if (is_int(common_config('http', 'timeout'))) { + // Reasonably you shouldn't set http/timeout to 0 because of + // malicious remote servers that can cause infinitely long + // responses... But the default in HTTP_Request2 is 0 for + // some reason and should probably be considered a valid value. + $this->config['timeout'] = common_config('http', 'timeout'); + } else { + common_log(LOG_ERR, 'config option http/timeout is not an integer value: '._ve(common_config('http', 'timeout'))); + } + if (!empty(common_config('http', 'connect_timeout'))) { + $this->config['connect_timeout'] = common_config('http', 'connect_timeout'); + } $this->config['max_redirs'] = 10; $this->config['follow_redirects'] = true; @@ -206,6 +217,29 @@ class HTTPClient extends HTTP_Request2 return $data; } + /** + * If you want an Accept header, put it in $headers + */ + public static function quickHead($url, array $params=array(), array $headers=array()) + { + if (!empty($params)) { + $params = http_build_query($params, null, '&'); + if (strpos($url, '?') === false) { + $url .= '?' . $params; + } else { + $url .= '&' . $params; + } + } + + $client = new HTTPClient(); + $response = $client->head($url, $headers); + if (!$response->isOk()) { + // TRANS: Exception. %s is the URL we tried to GET. + throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus()); + } + return $response->getHeader(); + } + /** * Convenience function to run a GET request. *