@param array $urls
@param array $options
@param array $securedDirCredentials

@return \Psr\Http\Message\StreamInterface|string

@throws \Exception
173696
public function sendRecommendationResponse(array $urls, $options, $securedDirCredentials)
    {
        $guzzle = new Client(array(
            'base_uri' => $options['webHook'],
        ));

        $events = array();

        foreach ($urls as $contentTypeId => $languages) {
            foreach ($languages as $lang => $contentTypeInfo) {
                $event = array(
                    'action' => 'FULL',
                    'format' => 'EZ',
                    'contentTypeId' => $contentTypeId,
                    'contentTypeName' => $contentTypeInfo['contentTypeName'],
                    'lang' => $lang,
                    'uri' => $contentTypeInfo['urlList'],
                    'credentials' => !empty($securedDirCredentials) ? $securedDirCredentials : null,
                );

                $events[] = $event;

                $this->logger->debug(sprintf(
                    'Event for eZ Recommendation server created: %s',
                    var_export($event, true)
                ));
            }
        }

        try {
            $req = new Request(
                'POST',
                '',
                array(
                    'Content-Type' => 'application/json',
                    'Authorization' => 'Basic ' . base64_encode($options['customerId'] . ':' . $options['licenseKey']),
                ),
                json_encode(array(
                    'transaction' => $options['transaction'],
                    'events' => $events,
                ))
            );

            $response = $guzzle->send(
                $req, [
                    'debug' => $this->debug,
                ]
            )->getBody();

            $this->logger->info(sprintf(
                'Request has been sent to recommendation server with transaction: %s and %s events',
                $options['transaction'], count($events)
            ));
        } catch (\Exception $e) {
            $this->logger->error(sprintf(
                'Error while sending data to eZ Recommendation server %s %s %s %s',
                $e->getMessage(), $e->getCode(), $e->getFile(), $e->getLine()
            ));

            throw $e;
        }

        return $response;
    }
472594
protected function tlsStreamInitializer(ParametersInterface $parameters)
    {
        $resource = $this->tcpStreamInitializer($parameters);
        $metadata = stream_get_meta_data($resource);

        // Detect if crypto mode is already enabled for this stream (PHP >= 7.0.0).
        if (isset($metadata['crypto'])) {
            return $resource;
        }

        if (is_array($parameters->ssl)) {
            $options = $parameters->ssl;
        } else {
            $options = array();
        }

        if (!isset($options['crypto_type'])) {
            $options['crypto_type'] = STREAM_CRYPTO_METHOD_TLS_CLIENT;
        }

        if (!stream_context_set_option($resource, array('ssl' => $options))) {
            $this->onConnectionError('Error while setting SSL context options');
        }

        if (!stream_socket_enable_crypto($resource, true, $options['crypto_type'])) {
            $this->onConnectionError('Error while switching to encrypted communication');
        }

        return $resource;
    }
1020118
protected function initRequest($url, $options = array()) {
		$ch = parent::initRequest($url, $options);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
		return $ch;
	}
1231427
public function getSecureURL($expires = 60) {
		if($this->owner instanceof \Image_Cached || $this->owner instanceof \CdnImage_Cached) {
			return;
		}

		/** @var \FileContent $pointer */
		$pointer = $this->owner->obj('CDNFile');

		if($pointer->exists()) {
			$reader = $this->reader();
			if ($reader && $this->owner->canView() && method_exists($reader, 'getSecureURL')) {
				return $reader->getSecureURL($expires);
			}
		}
	}
947415
protected function configureURL(array $options)
    {
        $url = $this->getEndPointUrl();
        if ($this->requiresOptions()) {
            $urlArr = explode("/",$url);
            $optional = FALSE;
            $optionNum = 0;
            $keys = array_keys($options);
            sort($keys);
            foreach($keys as $key){
                if (is_numeric($key)){
                    $optionNum = $key;
                    break;
                }
            }
            foreach($urlArr as $key => $urlPart){
                $replace = NULL;
                if (strpos($urlPart,static::$_URL_VAR_CHARACTER) !== FALSE){
                    if (strpos($urlPart,':') !== FALSE){
                        $optional = TRUE;
                        $replace = '';
                    }
                    $opt = str_replace(array(static::$_URL_VAR_CHARACTER,':'),'',$urlPart);
                    if (isset($options[$opt])){
                        $replace = $options[$opt];
                    }
                    if (isset($options[$optionNum]) && ($replace == '' || $replace == NULL)){
                        $replace = $options[$optionNum];
                        $optionNum = $optionNum+1;
                    }
                    if ($optional && $replace == ''){
                        $urlArr = array_slice($urlArr,0,$key);
                        break;
                    }
                    if ($replace !== NULL){
                        $urlArr[$key] = $replace;
                    }
                }
            }
            $url = implode("/",$urlArr);
            $url = rtrim($url,"/");
        }
        return $url;
    }
1211752
protected function generateStandardUrl(array $urlParameters = array(), $absolute = false)
    {
        $urlParameters = $this->addRequestVariablesToUrlParameters($urlParameters);

        $anchor = '';
        if ($this->hasAnchor())
        {
            $anchor = '#'.$this->getAnchor();
        }

        return $this->getRouter()->generate($this->getRouteName(), $urlParameters, $absolute) . $anchor;
    }
1086095
public function formatEncryptionHeaders(array $options)
    {
        $encryptionHeaders = [];
        $useCopySourceHeaders = isset($options['useCopySourceHeaders']) ? $options['useCopySourceHeaders'] : false;
        $key = isset($options['encryptionKey']) ? $options['encryptionKey'] : null;
        $keySHA256 = isset($options['encryptionKeySHA256']) ? $options['encryptionKeySHA256'] : null;
        $destinationKey = isset($options['destinationEncryptionKey']) ? $options['destinationEncryptionKey'] : null;
        $destinationKeySHA256 = isset($options['destinationEncryptionKeySHA256'])
            ? $options['destinationEncryptionKeySHA256']
            : null;

        unset($options['useCopySourceHeaders']);
        unset($options['encryptionKey']);
        unset($options['encryptionKeySHA256']);
        unset($options['destinationEncryptionKey']);
        unset($options['destinationEncryptionKeySHA256']);

        $encryptionHeaders = $this->buildHeaders($key, $keySHA256, $useCopySourceHeaders)
            + $this->buildHeaders($destinationKey, $destinationKeySHA256, false);

        if (!empty($encryptionHeaders)) {
            if (isset($options['restOptions']['headers'])) {
                $options['restOptions']['headers'] += $encryptionHeaders;
            } else {
                $options['restOptions']['headers'] = $encryptionHeaders;
            }
        }

        return $options;
    }
1280820
public function purgeUrls(array $urls)
    {
        if (strpos($this->domain, 'http') !== 0) {
            throw new \InvalidArgumentException("'domain' must include the protocol, e.g. https://www.foo.com");
        }

        // prefix urls with domain
        $files = array_map(function ($url) {
            return rtrim($this->domain, '/') . $url;
        }, $urls);

        // Chunk larger collections to meet the API constraints
        foreach(array_chunk($files, self::MAX_URLS_PER_PURGE) as $fileGroup) {
            $this->sendRequest('DELETE', 'purge_cache', [
                'files' => $fileGroup
            ]);
        }

        return true;
    }
444161
public function redirectTo($url, array $options = array())
    {
        $options = new Hash($options);
        $this->redirectUrl = $url;
        $this->setStatusCode($options->fetch('status', 302));

        $this->getHeaders()->offsetSet('Location', $url);

        return $this;
    }
703635
public function getAuthenticatedRequest($method, $url, $token, array $options = [])
    {
        $baseUri = new Psr7\Uri($this->urlApiDomain);
        $relativeUri = new Psr7\Uri($url);
        $newUri = Psr7\Uri::resolve($baseUri, $relativeUri);

        return parent::getAuthenticatedRequest($method, $newUri, $token, $options);
    }
544900
public function route($name, $parameters = [], $secure = null)
    {
        if (! isset($this->app->router->namedRoutes[$name])) {
            throw new \InvalidArgumentException("Route [{$name}] not defined.");
        }

        $uri = $this->app->router->namedRoutes[$name];

        $parameters = $this->formatParameters($parameters);

        $uri = \preg_replace_callback('/\[([^\]]*)\]$/', function ($matches) use ($uri, &$parameters) {
            $uri = $this->replaceRouteParameters($matches[1], $parameters);

            return ($matches[1] == $uri) ? '' : $uri;
        }, $uri);

        $uri = $this->replaceRouteParameters($uri, $parameters);

        $uri = $this->to($uri, [], $secure);

        if (! empty($parameters)) {
            $uri .= '?'.\http_build_query($parameters);
        }

        return $uri;
    }
693461
public static function toUrl(string $path, string $text, $parameters = [], $secure = null)
    {
        return static::to(url($path, $parameters, $secure), $text);
    }
687603
public function script($url, $attributes = [], $secure = null)
    {
        $attributes['src'] = asset($url, $secure);

        return '<script'.attr($attributes).'></script>'.PHP_EOL;
    }
2868
public function getRedirectUrlBase()
    {
        // URLConfirmationTokens may alter the URL to suppress the URL they're protecting,
        // so we need to ensure they're inspected last and therefore take priority
        $tokens = iterator_to_array($this->filteredTokens(), false);
        usort($tokens, function ($a, $b) {
            return ($a instanceof URLConfirmationToken) ? 1 : 0;
        });

        $urlBase = Director::baseURL();
        foreach ($tokens as $token) {
            $urlBase = $token->getRedirectUrlBase();
        }

        return $urlBase;
    }
1088532
protected function httpBuildQuery($url, array $options)
    {
        if (!empty($options)) {
            $url .= (stripos($url, '?') === null ? '&' : '?') . http_build_query($options);
        }
        return $url;
    }
429739
public function redirectIntended($path, $status = 302, $headers = [], $secure = null)
    {
        return Redirect::intended($this->uri() . '/' . $path, $status, $headers, $secure);
    }
50219
public function script($url, $attributes = [], $secure = null)
    {
        $attributes['src'] = $this->url->asset($url, $secure);

        return $this->toHtmlString('<script' . $this->attributes($attributes) . '></script>');
    }