From 6b689ffcce08dacd212b3d6914a2934d9a6fd247 Mon Sep 17 00:00:00 2001 From: ljm42 Date: Fri, 10 May 2024 12:57:57 -0700 Subject: [PATCH] Chore: sync http_get_contents() with webgui (#883) --- plugin/plugins/dynamix.unraid.net.plg | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugin/plugins/dynamix.unraid.net.plg b/plugin/plugins/dynamix.unraid.net.plg index 1a07d5410..c3051aff3 100755 --- a/plugin/plugins/dynamix.unraid.net.plg +++ b/plugin/plugins/dynamix.unraid.net.plg @@ -594,22 +594,29 @@ function http_get_contents(string $url, array $opts = [], array &$getinfo = NULL curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_REFERER, ""); curl_setopt($ch, CURLOPT_FAILONERROR, true); + curl_setopt($ch, CURLOPT_USERAGENT, 'Unraid'); if(is_array($opts) && $opts) { foreach($opts as $key => $val) { curl_setopt($ch, $key, $val); } } $out = curl_exec($ch); - if(isset($getinfo)) { + if (curl_errno($ch) == 23) { + // error 23 detected, try CURLOPT_ENCODING = "deflate" + curl_setopt($ch, CURLOPT_ENCODING, "deflate"); + $out = curl_exec($ch); + } + if (isset($getinfo)) { $getinfo = curl_getinfo($ch); } - if (curl_errno($ch)) { - $msg = curl_error($ch) . " {$url}"; + if ($errno = curl_errno($ch)) { + $msg = "Curl error $errno: " . (curl_error($ch) ?: curl_strerror($errno)) . ". Requested url: '$url'"; if(isset($getinfo)) { $getinfo['error'] = $msg; } my_logger($msg, "http_get_contents"); } + curl_close($ch); return $out; } END_HEREDOC