From 969b41c1c95239796c5eb98a8dac71b5ea367043 Mon Sep 17 00:00:00 2001 From: cbhp Date: Sun, 31 Aug 2014 19:44:06 +0200 Subject: [PATCH 1/2] added missing User-Agents header "User-Agent" was missed --- lib/private/util.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/util.php b/lib/private/util.php index adb7fb83d28..1711dd7cf01 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -1303,6 +1303,7 @@ class OC_Util { curl_setopt($rcurl, CURLOPT_NOBODY, true); curl_setopt($rcurl, CURLOPT_FORBID_REUSE, false); curl_setopt($rcurl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($rcurl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); do { curl_setopt($rcurl, CURLOPT_URL, $newURL); $header = curl_exec($rcurl); @@ -1337,6 +1338,7 @@ class OC_Util { if (OC_Config::getValue('proxy', '') != '') { $contextArray = array( 'http' => array( + 'header' => "User-Agent: ownCloud Server Crawler\r\n", 'timeout' => 10, 'proxy' => OC_Config::getValue('proxy') ) @@ -1344,6 +1346,7 @@ class OC_Util { } else { $contextArray = array( 'http' => array( + 'header' => "User-Agent: ownCloud Server Crawler\r\n", 'timeout' => 10 ) ); From c00450b2c715d5928af4ff3f1b8489cd69128c99 Mon Sep 17 00:00:00 2001 From: cbhp Date: Wed, 3 Sep 2014 18:00:05 +0200 Subject: [PATCH 2/2] always use a user-agent constant Some providers block connections with missing user-agents. Also user-agents are useful for analyzing requests. I've added a USER_AGENT constant that is used in cURL and in file_get_contents. --- lib/private/util.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/private/util.php b/lib/private/util.php index 1711dd7cf01..7c427f20a23 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -5,6 +5,8 @@ * */ class OC_Util { + const USER_AGENT = 'ownCloud Server Crawler'; + public static $scripts = array(); public static $styles = array(); public static $headers = array(); @@ -1281,7 +1283,7 @@ class OC_Util { curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + curl_setopt($curl, CURLOPT_USERAGENT, self::USER_AGENT); if (OC_Config::getValue('proxy', '') != '') { curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy')); } @@ -1303,7 +1305,7 @@ class OC_Util { curl_setopt($rcurl, CURLOPT_NOBODY, true); curl_setopt($rcurl, CURLOPT_FORBID_REUSE, false); curl_setopt($rcurl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($rcurl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + curl_setopt($rcurl, CURLOPT_USERAGENT, self::USER_AGENT); do { curl_setopt($rcurl, CURLOPT_URL, $newURL); $header = curl_exec($rcurl); @@ -1338,7 +1340,7 @@ class OC_Util { if (OC_Config::getValue('proxy', '') != '') { $contextArray = array( 'http' => array( - 'header' => "User-Agent: ownCloud Server Crawler\r\n", + 'header' => 'User-Agent: ' . self::USER_AGENT . "\r\n", 'timeout' => 10, 'proxy' => OC_Config::getValue('proxy') ) @@ -1346,7 +1348,7 @@ class OC_Util { } else { $contextArray = array( 'http' => array( - 'header' => "User-Agent: ownCloud Server Crawler\r\n", + 'header' => 'User-Agent: ' . self::USER_AGENT . "\r\n", 'timeout' => 10 ) );