<commit_before><?php

/**
 * @package    Grav\Common\GPM
 *
 * @copyright  Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved.
 * @license    MIT License; see LICENSE file for details.
 */

namespace Grav\Common\GPM;

use Exception;
use Grav\Common\Utils;
use Grav\Common\Grav;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Component\HttpClient\NativeHttpClient;
use function call_user_func;
use function function_exists;

/**
 * Class Response
 * @package Grav\Common\GPM
 */
class Response
{
    /** @var callable    The callback for the progress, either a function or callback in array notation */
    public static $callback = null;

    private static $headers = [
        'User-Agent' => 'Grav CMS'
    ];

    /**
     * Makes a request to the URL by using the preferred method
     *
     * @param string $uri URL to call
     * @param array $overrides An array of parameters for both `curl` and `fopen`
     * @param callable|null $callback Either a function or callback in array notation
     * @return string The response of the request
     * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
     */
    public static function get($uri = '', $overrides = [], $callback = null)
    {
        if (empty($uri)) {
            throw new TransportException('missing URI');
        }

        // check if this function is available, if so use it to stop any timeouts
        try {
            if (function_exists('set_time_limit') && !Utils::isFunctionDisabled('set_time_limit')) {
                set_time_limit(0);
            }
        } catch (Exception $e) {
        }

        $config = Grav::instance()['config'];
        $referer = Grav::instance()['uri']->rootUrl(true);
        $options = new HttpOptions();

        // Set default Headers
        $options->setHeaders(array_merge([ 'Referer' => $referer ], self::$headers));<commit_msg>Set grav_cli as referer when coming from CLI<commit_after><?php

/**
 * @package    Grav\Common\GPM
 *
 * @copyright  Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved.
 * @license    MIT License; see LICENSE file for details.
 */

namespace Grav\Common\GPM;

use Exception;
use Grav\Common\Utils;
use Grav\Common\Grav;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Component\HttpClient\NativeHttpClient;
use function call_user_func;
use function function_exists;

/**
 * Class Response
 * @package Grav\Common\GPM
 */
class Response
{
    /** @var callable    The callback for the progress, either a function or callback in array notation */
    public static $callback = null;

    private static $headers = [
        'User-Agent' => 'Grav CMS'
    ];

    /**
     * Makes a request to the URL by using the preferred method
     *
     * @param string $uri URL to call
     * @param array $overrides An array of parameters for both `curl` and `fopen`
     * @param callable|null $callback Either a function or callback in array notation
     * @return string The response of the request
     * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
     */
    public static function get($uri = '', $overrides = [], $callback = null)
    {
        if (empty($uri)) {
            throw new TransportException('missing URI');
        }

        // check if this function is available, if so use it to stop any timeouts
        try {
            if (function_exists('set_time_limit') && !Utils::isFunctionDisabled('set_time_limit')) {
                set_time_limit(0);
            }
        } catch (Exception $e) {
        }

        $config = Grav::instance()['config'];
        $referer = \defined('GRAV_CLI') ? 'grav_cli' : Grav::instance()['uri']->rootUrl(true);
        $options = new HttpOptions();

        // Set default Headers
        $options->setHeaders(array_merge([ 'Referer' => $referer ], self::$headers));
{'fraction_non_alphanumeric': 0.11286089238845144, 'fraction_numerical': 0.004294917680744453, 'mean_word_length': 3.0038204393505255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3386043', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1165, 'n_words': 358}