/** * Makes a request to the URL by using the preferred method * * @param string $uri URL to call * @param array $options An array of parameters for both `curl` and `fopen` * @param callable $callback Either a function or callback in array notation * * @return string The response of the request */ public static function get($uri = '', $options = [], $callback = null) { if (!self::isCurlAvailable() && !self::isFopenAvailable()) { throw new \RuntimeException('Could not start an HTTP request. `allow_url_open` is disabled and `cURL` is not available'); } // check if this function is available, if so use it to stop any timeouts try { if (!Utils::isFunctionDisabled('set_time_limit') && !ini_get('safe_mode') && function_exists('set_time_limit')) { set_time_limit(0); } } catch (\Exception $e) { } $options = array_replace_recursive(self::$defaults, $options); $method = 'get' . ucfirst(strtolower(self::$method)); self::$callback = $callback; return static::$method($uri, $options, $callback); }
/** * Makes a request to the URL by using the preferred method * * @param string $uri URL to call * @param array $options An array of parameters for both `curl` and `fopen` * @param callable $callback Either a function or callback in array notation * * @return string The response of the request */ public static function get($uri = '', $options = [], $callback = null) { if (!self::isCurlAvailable() && !self::isFopenAvailable()) { throw new \RuntimeException('Could not start an HTTP request. `allow_url_open` is disabled and `cURL` is not available'); } // check if this function is available, if so use it to stop any timeouts try { if (!Utils::isFunctionDisabled('set_time_limit') && !ini_get('safe_mode') && function_exists('set_time_limit')) { set_time_limit(0); } } catch (\Exception $e) { } $config = Grav::instance()['config']; $overrides = []; // SSL Verify Peer and Proxy Setting $settings = ['method' => $config->get('system.gpm.method', self::$method), 'verify_peer' => $config->get('system.gpm.verify_peer', true), 'proxy_url' => $config->get('system.gpm.proxy_url', $config->get('system.proxy_url', false))]; if (!$settings['verify_peer']) { $overrides = array_replace_recursive([], $overrides, ['curl' => [CURLOPT_SSL_VERIFYPEER => $settings['verify_peer']], 'fopen' => ['ssl' => ['verify_peer' => $settings['verify_peer'], 'verify_peer_name' => $settings['verify_peer']]]]); } // Proxy Setting if ($settings['proxy_url']) { $proxy = parse_url($settings['proxy_url']); $fopen_proxy = ($proxy['scheme'] ?: 'http') . '://' . $proxy['host'] . (isset($proxy['port']) ? ':' . $proxy['port'] : ''); $overrides = array_replace_recursive([], $overrides, ['curl' => [CURLOPT_PROXY => $proxy['host'], CURLOPT_PROXYTYPE => 'HTTP'], 'fopen' => ['proxy' => $fopen_proxy, 'request_fulluri' => true]]); if (isset($proxy['port'])) { $overrides['curl'][CURLOPT_PROXYPORT] = $proxy['port']; } if (isset($proxy['user']) && isset($proxy['pass'])) { $fopen_auth = $auth = base64_encode($proxy['user'] . ':' . $proxy['pass']); $overrides['curl'][CURLOPT_PROXYUSERPWD] = $proxy['user'] . ':' . $proxy['pass']; $overrides['fopen']['header'] = "Proxy-Authorization: Basic {$fopen_auth}"; } } $options = array_replace_recursive(self::$defaults, $options, $overrides); $method = 'get' . ucfirst(strtolower($settings['method'])); self::$callback = $callback; return static::$method($uri, $options, $callback); }