Do an actual request to the specified URL

@todo don't use curl, use guzzle
@param $url
@param bool $content
@param bool $customRequest
@return mixed
161100
public function request($url, $content = false, $customRequest = false)
    {

        $request_parts = explode('/', $url);
        $request = $request_parts[3];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        if(strpos($url,'test')){
            curl_setopt($ch, CURLOPT_USERPWD,
                $this->username . ":" . $this->testPassword);
        }else{
            curl_setopt($ch, CURLOPT_USERPWD,
                $this->username . ":" . $this->password);
        }

        curl_setopt($ch, CURLOPT_HTTPHEADER,
            array("Content-Type:application/xml;charset=UTF-8"));

        if ($content && !$customRequest) {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
        }

        if ($customRequest) {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $customRequest);
        }

        $output = curl_exec($ch);

        $outputINFO = curl_getinfo($ch);

        $this->log([
            "httpcode" => $outputINFO['http_code'],
            "url" => $url,
            "endpoint" => $request,
            "output" => $output
        ]);

        if ($outputINFO['http_code'] >= 400 || curl_errno($ch)) {
            $this->log(curl_error($ch), "error");
            $this->log($output, "error");
        } else {
            $this->log(".datacite.".$request.".response:".$output);
        }

        curl_close($ch);
        return $output;
    }
700679
private function matchCustomUrl($url, PortalInformation $portalInformation, Request $request)
    {
        $webspace = $portalInformation->getWebspace();
        $routeDocument = $this->customUrlManager->findRouteByUrl(
            rawurldecode($url),
            $webspace->getKey()
        );

        if (!$routeDocument) {
            return [];
        } elseif ($routeDocument->isHistory()) {
            // redirect happen => no portal is needed
            return ['customUrlRoute' => $routeDocument];
        }

        $customUrlDocument = $this->customUrlManager->findByUrl(
            rawurldecode($url),
            $webspace->getKey(),
            $routeDocument->getTargetDocument()->getTargetLocale()
        );

        if (null === $customUrlDocument
            || false === $customUrlDocument->isPublished()
            || null === $customUrlDocument->getTargetDocument()
            || WorkflowStage::PUBLISHED !== $customUrlDocument->getTargetDocument()->getWorkflowStage()
        ) {
            // error happen because this custom-url is not published => no portal is needed
            return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
        }

        $localization = Localization::createFromString($customUrlDocument->getTargetLocale());

        $portalInformations = $this->webspaceManager->findPortalInformationsByWebspaceKeyAndLocale(
            $portalInformation->getWebspace()->getKey(),
            $localization->getLocale(),
            $this->environment
        );

        if (0 === count($portalInformations)) {
            return ['customUrlRoute' => $routeDocument, 'customUrl' => $customUrlDocument];
        }

        return [
            'portalInformation' => $portalInformation,
            'localization' => $localization,
            'locale' => $localization->getLocale(),
            'customUrlRoute' => $routeDocument,
            'customUrl' => $customUrlDocument,
            'urlExpression' => $this->generator->generate(
                $customUrlDocument->getBaseDomain(),
                $customUrlDocument->getDomainParts()
            ),
        ];
    }
395667
protected function request($url,$context)
    {
        if (function_exists('curl_version')) {
            $ch = curl_init();
            if (array_key_exists("http", $context)) {
                if (array_key_exists('method', $context["http"])) {
                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $context["http"]["method"]);
                }
                if (array_key_exists("header", $context["http"])) {
                    $delimiter = strpos($context["http"]["header"], "\r\n") === false ? "\n" : "\r\n";
                    $headers = array_filter(explode($delimiter, $context["http"]["header"]), function($item) {
                        return !is_null($item);
                    });
                    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                }
                if (array_key_exists("content", $context["http"])) {
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $context["http"]["content"]);    
                }
            }
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_URL,$url);
            $result = curl_exec($ch);
            curl_close($ch);
            return $result;
        }

        return file_get_contents($url,false,stream_context_create($context));
    }
1076518
public function head($url, array $customHeaders = [])
    {
        return $this->handleFailover(function() use ($url, $customHeaders) {
            $response = $this->executeRequest(HttpHelper::METHOD_HEAD, $url, '', $customHeaders);

            return $this->parseResponse($response);
        });
    }
446004
public function getPage(string $url = null): Page
	{
		$page = $this->orm->pages->getByUrl($url, $this->translator->getLocale());
		if (!$page || !$page->visible) {
			throw new BadRequestException(null, IResponse::S404_NOT_FOUND);
		}
		return $page;
	}
832418
public static function currentUrl(bool $includeQuery = true, bool $urlEncode = false)
    {
        if (RequestHelper::isCli()) {
            return null;
        }

        $url = static::protocolHostPort() . static::currentUri($includeQuery, $urlEncode);

        return $urlEncode ? urlencode($url) : $url;
    }
1258421
public function request($url, $requestData) {
        $request = new CurlRequest($url);
        $request->setPostData($requestData);

        $this->setOptionsOnRequest($request, $this->options);

        return $request->execute();
    }
331607
protected function doRequest($url, $method, $data, $contentType = null, $filePath = null)
  {
    if($method == 'FILE')
      $url = $this->uploadUrl . $url;
    else
      $url = $this->url . $url;

    if($this->debug){
      echo "URL: $url\n";
      echo "Data: " . print_r($data, true) . "\n";
    }

    $c = curl_init();

    curl_setopt($c, CURLOPT_VERBOSE, $this->debug);

    if($this->username && $this->password){
      curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($c, CURLOPT_USERPWD, "$this->username:$this->password");
    }

    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_USERAGENT, "tan-tan.github-api");
    curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
    curl_setopt($c, CURLOPT_HEADER, true);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);

    if(is_array($data)){
      foreach($data as $key => $value){
        if(is_bool($value))
          $data[$key] = $value ? 'true' : 'false';
      }
    }

    switch($method){
      case 'FILE':
        curl_setopt($c, CURLOPT_HTTPHEADER, array("Content-type: $contentType"));
        curl_setopt($c, CURLOPT_POST, true);
        curl_setopt($c, CURLOPT_POSTFIELDS, file_get_contents($filePath));

        if(count($data))
          $url .= '?' . http_build_query($data);
        break;

      case 'GET':
        curl_setopt($c, CURLOPT_HTTPGET, true);
        if(count($data))
          $url .= '?' . http_build_query($data);
        break;

      case 'POST':
        curl_setopt($c, CURLOPT_POST, true);
        if(count($data))
          curl_setopt($c, CURLOPT_POSTFIELDS, $data);
        break;

      case 'PUT':
        curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'PUT');
        curl_setopt($c, CURLOPT_PUT, true);

        $headers = array('X-HTTP-Method-Override: PUT', 'Content-type: application/x-www-form-urlencoded');

        if(count($data)){
          $content = json_encode($data, JSON_FORCE_OBJECT);

          $fileName = tempnam(sys_get_temp_dir(), 'gitPut');
          file_put_contents($fileName, $content);

          $f = fopen($fileName, 'rb');
          curl_setopt($c, CURLOPT_INFILE, $f);
          curl_setopt($c, CURLOPT_INFILESIZE, strlen($content));
        }
        curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
        break;

      case 'PATCH':
      case 'DELETE':
        curl_setopt($c, CURLOPT_CUSTOMREQUEST, $method);

        if($data){
          curl_setopt($c, CURLOPT_POST, true);
          curl_setopt($c, CURLOPT_POSTFIELDS, $data);
        }
        break;
    }

    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);

    $response = curl_exec($c);

    curl_close($c);

    if($this->debug)
      echo "Response:\n$response\n";

    return $response;
  }
24375
public function setUrl(string $url): RequestContext
    {
        $this->assertValidUrl($url);

        $this->url = $url;

        return $this;
    }
1362596
public function get($url, $data = array())
    {
        if (is_array($url)) {
            $data = $url;
            $url = $this->baseUrl;
        }
        $this->setUrl($url, $data);
        $this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
        $this->setOpt(CURLOPT_HTTPGET, true);
        return $this->exec();
    }
488638
protected function _makeFOpenRequest($url)
    {
        $context      = $this->_buildFOpenStreamContext();
        $file_pointer = @fopen($url, 'r', null, $context);

        if(!$file_pointer)
            throw new Exception("There was an error making the request. Make sure that the url is valid, and either fopen or cURL are available.");

        $meta    = stream_get_meta_data($file_pointer);
        $headers = $this->_buildResponseHeaderFromMeta($meta);
        $content = stream_get_contents($file_pointer);

        fclose($file_pointer);

        return "$headers\r\n\r\n$content";
    }
202581
protected function execute($url, $content, $tries)
  {
    echo "sending request $content to $url";

    return Request::post($url . "?retry=$tries")
        ->body($content)
        ->timeout(isset($this->timeout) ? $this->timeout : self::DEFAULT_TIMEOUT)
        ->addOnCurlOption(CURLOPT_CONNECTTIMEOUT_MS, (isset($this->connectTimeout) ? $this->connectTimeout : self::DEFAULT_CONNECT_TIMEOUT) * 1000)
        ->sendsType(Mime::JSON)
        ->send();
  }
1124167
public function put($url, $content = '')
    {
        $req = $url instanceof Request ? $url : $this->buildRequest('PUT', $url);
        $req->setBody($content);
        return $this->exec($req);
    }
557524
public function options($url, $data = array())
    {
        if (is_array($url)) {
            $data = $url;
            $url = $this->baseUrl;
        }
        $this->setURL($url, $data);
        $this->unsetHeader('Content-Length');
        $this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
        return $this->exec();
    }
1077378
private function query($url, $content, $class)
  {
    $response = null;
    $tries = 0;
    $lastError = null;

    while ($tries < self::MAX_TRIES) {
      try {
        $response = $this->execute($url, $content, $tries);
        break;
      } catch (Exception $e) {
        usleep(self::RETRY_TIMEOUT);
        error_log('Connection failed, retrying');
        $lastError = $e;
        $tries++;
      }
    }

    if ($tries == self::MAX_TRIES) {
      throw new RuntimeException("Error: call to URL $url failed after " . self::MAX_TRIES . " tries", 0, $lastError);
    }

    if ($response->hasErrors()) {
      throw new RuntimeException("Error: call to URL $url failed with status $response->code, response $response");
    }

    if ($response->content_type !== Mime::JSON) {
      throw new RuntimeException("Error: bridge at URL $url did not return the expected JSON response, it returned: " . $response->content_type . " instead");
    }

    $responseBody = $response->raw_body;
    if (strpos($this->getContentEncoding($response), 'gzip') !== FALSE) {
      $responseBody = gzdecode($responseBody);
    }

    return $this->deserialize($responseBody, $class);
  }
1211489
function request($url,array $options=NULL) {
		$fw=Base::instance();
		$parts=parse_url($url);
		if (empty($parts['scheme'])) {
			// Local URL
			$url=$fw->SCHEME.'://'.$fw->HOST.
				(in_array($fw->PORT,[80,443])?'':(':'.$fw->PORT)).
				($url[0]!='/'?($fw->BASE.'/'):'').$url;
			$parts=parse_url($url);
		}
		elseif (!preg_match('/https?/',$parts['scheme']))
			return FALSE;
		if (!is_array($options))
			$options=[];
		if (empty($options['header']))
			$options['header']=[];
		elseif (is_string($options['header']))
			$options['header']=[$options['header']];
		if (!$this->wrapper)
			$this->engine();
		if ($this->wrapper!='stream') {
			// PHP streams can't cope with redirects when Host header is set
			$this->subst($options['header'],'Host: '.$parts['host']);
		}
		$this->subst($options['header'],
			[
				'Accept-Encoding: gzip,deflate',
				'User-Agent: '.(isset($options['user_agent'])?
					$options['user_agent']:
					'Mozilla/5.0 (compatible; '.php_uname('s').')'),
				'Connection: close'
			]
		);
		if (isset($options['content']) && is_string($options['content'])) {
			if ($options['method']=='POST' &&
				!preg_grep('/^Content-Type:/i',$options['header']))
				$this->subst($options['header'],
					'Content-Type: application/x-www-form-urlencoded');
			$this->subst($options['header'],
				'Content-Length: '.strlen($options['content']));
		}
		if (isset($parts['user'],$parts['pass']))
			$this->subst($options['header'],
				'Authorization: Basic '.
					base64_encode($parts['user'].':'.$parts['pass'])
			);
		$options+=[
			'method'=>'GET',
			'header'=>$options['header'],
			'follow_location'=>TRUE,
			'max_redirects'=>20,
			'ignore_errors'=>FALSE
		];
		$eol="\r\n";
		if ($fw->CACHE &&
			preg_match('/GET|HEAD/',$options['method'])) {
			$cache=Cache::instance();
			if ($cache->exists(
				$hash=$fw->hash($options['method'].' '.$url).'.url',$data)) {
				if (preg_match('/Last-Modified: (.+?)'.preg_quote($eol).'/',
					implode($eol,$data['headers']),$mod))
					$this->subst($options['header'],
						'If-Modified-Since: '.$mod[1]);
			}
		}
		$result=$this->{'_'.$this->wrapper}($url,$options);
		if ($result && isset($cache)) {
			if (preg_match('/HTTP\/1\.\d 304/',
				implode($eol,$result['headers']))) {
				$result=$cache->get($hash);
				$result['cached']=TRUE;
			}
			elseif (preg_match('/Cache-Control:(?:.*)max-age=(\d+)(?:,?.*'.
				preg_quote($eol).')/i',implode($eol,$result['headers']),$exp))
				$cache->set($hash,$result,$exp[1]);
		}
		$req=[$options['method'].' '.$url];
		foreach ($options['header'] as $header)
			array_push($req,$header);
		return array_merge(['request'=>$req],$result);
	}
573493
public static function getByType(string $type, string $content = null): ResponseContextAbstract
    {
        switch ($type) {
            case self::RESPONSE_TYPE_JSON:
                return new JsonResponseContext($content);
            default:
                return new DummyResponseContext($content);
        }
    }