diff --git a/classes/urlhelper.php b/classes/urlhelper.php
index 83f66a810e1696f59621c4352da30c4a0e3e4a20..637ad1a44b28539c2cc08034bbea70f1275930af 100644
--- a/classes/urlhelper.php
+++ b/classes/urlhelper.php
@@ -394,6 +394,11 @@ class UrlHelper {
 
 			$ret = @curl_exec($ch);
 
+			if (curl_errno($ch) === 23 || curl_errno($ch) === 61) {
+				curl_setopt($ch, CURLOPT_ENCODING, 'none');
+				$contents = @curl_exec($ch);
+			}
+
 			$headers_length = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
 			$headers = explode("\r\n", substr($ret, 0, $headers_length));
 			$contents = substr($ret, $headers_length);
@@ -413,11 +418,6 @@ class UrlHelper {
 				}
 			}
 
-			if (curl_errno($ch) === 23 || curl_errno($ch) === 61) {
-				curl_setopt($ch, CURLOPT_ENCODING, 'none');
-				$contents = @curl_exec($ch);
-			}
-
 			$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 			self::$fetch_last_content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);