distroquery.php: add a 15 seconds timeout to all API requests

This commit is contained in:
Silvan Calarco 2024-12-07 00:43:56 +01:00
parent 00584e2f08
commit 06122a2040

View File

@ -42,6 +42,11 @@ $url_prefix = home_url() . "/rpms/";
$package=get_query_var('package'); $package=get_query_var('package');
$arch=get_query_var('arch'); $arch=get_query_var('arch');
$get_args = array(
'timeout' => 15,
'sslverify' => false
);
if ($repo == "") { if ($repo == "") {
// //
@ -50,7 +55,7 @@ $url_prefix = home_url() . "/rpms/";
echo " > " . _r("Repositories"); echo " > " . _r("Repositories");
echo "<h1>" . _r("Available repositories") . ":</h1>"; echo "<h1>" . _r("Available repositories") . ":</h1>";
$request = wp_remote_get($api_url . "repositories"); $request = wp_remote_get($api_url . "repositories", $get_args);
if (is_wp_error($request)) { if (is_wp_error($request)) {
echo "<p>ERROR: " . $request->get_error_message() . "</p>"; echo "<p>ERROR: " . $request->get_error_message() . "</p>";
goto finish; goto finish;
@ -75,7 +80,7 @@ $url_prefix = home_url() . "/rpms/";
if ($q != "") $query_append .= "&q=" . urlencode($q); if ($q != "") $query_append .= "&q=" . urlencode($q);
if (strlen($query_append) > 0 && $query_append[0] == '&') $query_append[0] = "?"; if (strlen($query_append) > 0 && $query_append[0] == '&') $query_append[0] = "?";
$request = wp_remote_get($api_url . "repository/" . $repo . $query_append); $request = wp_remote_get($api_url . "repository/" . $repo . $query_append, $get_args);
if (is_wp_error($request)) { if (is_wp_error($request)) {
echo "<p>ERROR: " . $request->get_error_message() . "</p>"; echo "<p>ERROR: " . $request->get_error_message() . "</p>";
goto finish; goto finish;
@ -176,7 +181,7 @@ $url_prefix = home_url() . "/rpms/";
// //
echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>"; echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>";
$request = wp_remote_get($api_url . "package/" . $repo . "/" . $package); $request = wp_remote_get($api_url . "package/" . $repo . "/" . $package, $get_args);
if (is_wp_error($request)) { if (is_wp_error($request)) {
echo "<p>ERROR: " . $request->get_error_message() . "</p>"; echo "<p>ERROR: " . $request->get_error_message() . "</p>";
goto finish; goto finish;
@ -278,8 +283,7 @@ $url_prefix = home_url() . "/rpms/";
// //
echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>"; echo " > <a href=\"" . $url_prefix . "\">" . _r("Repositories") . "</a>";
$request = wp_remote_get($api_url . "package/" . $repo . "/" . $package . "/" . $arch, $request = wp_remote_get($api_url . "package/" . $repo . "/" . $package . "/" . $arch, $get_args);
array('timeout' => 15));
if (is_wp_error($request)) { if (is_wp_error($request)) {
echo "<div class=\"errorbox\">ERROR: " . $request->get_error_message() . "</div>"; echo "<div class=\"errorbox\">ERROR: " . $request->get_error_message() . "</div>";
goto finish; goto finish;