From 30fa3f7d42610d4aa81ea49a7b92ab086fd4ea1a Mon Sep 17 00:00:00 2001 From: Alex Barth <alex_b@53995.no-reply.drupal.org> Date: Wed, 8 Sep 2010 14:50:24 +0000 Subject: [PATCH] #671538 mburak: Use CURLOPT_TIMEOUT to limit download time of feeds. --- CHANGELOG.txt | 1 + libraries/http_request.inc | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 80511169..747391e5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXX -------------------------------- +- #671538 mburak: Use CURLOPT_TIMEOUT to limit download time of feeds. - #878002 Will White, David Goode: Support multiple sources per mapping target in FeedsDataProcessor. - #904804 alex_b: Support exportable vocabularies. diff --git a/libraries/http_request.inc b/libraries/http_request.inc index 4ec7c9a8..28d32064 100644 --- a/libraries/http_request.inc +++ b/libraries/http_request.inc @@ -19,6 +19,11 @@ define('HTTP_REQUEST_PCRE_LINK_TAG', '/<link((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x0 */ define('HTTP_REQUEST_PCRE_TAG_ATTRIBUTES', '/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/'); +/** + * For cUrl specific errors. + */ +class HRCurlException extends Exception {} + /** * Discover RSS or atom feeds at the given URL. If document in given URL is an * HTML document, function attempts to discover RSS or Atom feeds. @@ -140,11 +145,15 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva curl_setopt($download, CURLOPT_HEADER, TRUE); curl_setopt($download, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($download, CURLOPT_ENCODING, ''); + curl_setopt($download, CURLOPT_TIMEOUT, variable_get('feeds_worker_time', 15)); if ($accept_invalid_cert) { curl_setopt($download, CURLOPT_SSL_VERIFYPEER, 0); } $header = ''; $data = curl_exec($download); + if (curl_error($download)) { + throw new HRCurlException(t('cURL error (@code) @error for @url', array('@code' => curl_errno($download), '@error' => curl_error($download), '@url' => $url)), curl_errno($download)); + } $header_size = curl_getinfo($download, CURLINFO_HEADER_SIZE); $header = substr($data, 0, $header_size - 1); $result->data = substr($data, $header_size); -- GitLab