Returns the HTTP origin header.

@param   boolean  $isInternal Only allow internal URLs
@return  HttpUrl|null  A HttpUrl object or NULL if no origin header could be found
503344
public function getOrigin($isInternal = true)
    {
        $origin = null;

        if ($this->_headers->has('Origin'))
        {
            try {
                $origin = $this->getObject('lib:http.url', [
                    'url' => $this->getObject('lib:filter.url')->sanitize($this->_headers->get('Origin'))
                ]);

                if($isInternal)
                {
                    $target_origin = $this->getUrl()->getHost();
                    $source_origin = $origin->getHost();

                    // Check if the source matches the target
                    if($target_origin !== $source_origin)
                    {
                        // Special case: check if the source is a subdomain of the target origin
                        if ('.'.$target_origin !== substr($source_origin, -1 * (strlen($target_origin)+1))) {
                            $origin = null;
                        }
                    }
                }
            }
            catch (\UnexpectedValueException $e) {}
        }

        return $origin;
    }
126592
private function getClientInternal($type = null) {
		if ($type != null) {
			if (isset($this->clients[$type])) {
				return $this->clients[$type];
			} else {
				throw new \Exception("No http client with type '$type' found.");
			}
		} else {
			foreach ($this->clients as $client) {
				if ($client->isSupported()) {
					return $client;
				}
			}
			throw new \Exception('No supported http client found.');
		}
	}
1374915
public function getAuth($errorOnNull = false)
    {
        if ($errorOnNull && !$this->auth) {
            $msg = 'No Auth object provided.  (HINT: Set your Auth data using '
                 . '"$API->setAuth(Auth $auth)" or $API\' constructor.  '
                 . 'See https://TODO for details.';
            throw new ApiException($msg);
        }

        return $this->auth;
    }
429462
public function getInternalRequestClient()
	{
		// if we didnt find one lets make one
		if (!$client = $this->findInternalClient())
		{
			if ($this->createInternalRequestClient())
			{
				$client = $this->findInternalClient();
			}
		}

		// return client
		return ($client) ? $client : null;
	}
950164
public function getOutUrl($ssl = null, $admin = null, $nativeImg = false)
    {
        $ssl = is_null($ssl) ? $this->isSsl() : $ssl;
        $admin = is_null($admin) ? $this->isAdmin() : $admin;

        if ($ssl) {
            if ($nativeImg && !$admin) {
                $url = $this->getSslShopUrl();
            } else {
                $url = $this->getConfigParam('sSSLShopURL');
                if (!$url && $admin) {
                    $url = $this->getConfigParam('sAdminSSLURL') . '../';
                }
            }
        } else {
            $url = ($nativeImg && !$admin) ? $this->getShopUrl() : $this->getConfigParam('sShopURL');
        }

        return $url . $this->_sOutDir . '/';
    }
970839
public static function getExternalIP()
    {
        $ip = \Cache::rememberForever('external-ip-address', function () {
            $response = Curl::get('http://ipinfo.io/ip');
            $ip = trim($response, "\t\r\n");
            try {
                $validator = Validator::make(['ip' => $ip], ['ip' => 'ip']);
                $validator->validate();
            } catch (ValidationException $e) {
                $ip = null;
            }

            return $ip;
        });

        return $ip;
    }
183544
public static function protocolHostPort()
    {
        if (RequestHelper::isCli()) {
            return null;
        }

        $isHttps = RequestHelper::isHttps();
        $protocol = 'http' . ($isHttps ? 's' : '');
        $serverName = $_SERVER['SERVER_NAME'];
        $serverPort = (int)$_SERVER['SERVER_PORT'];

        $protocolHostPort = $protocol . '://';

        if ((!$isHttps && $serverPort !== 80) || ($isHttps && $serverPort !== 443)) {
            $protocolHostPort .= $serverName . ':' . $serverPort;
        } else {
            $protocolHostPort .= $serverName;
        }

        return $protocolHostPort;
    }
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;
    }
1120115
protected function getUrl($url, $headers, $timeout): ResponseInterface
    {
        try {
            $options = $this->buildGuzzleOptions($headers, $timeout);
            $response = $this->requestFactory->request($url, 'GET', $options);
        } catch (ClientException $e) {
            $response = $e->getResponse();
        } catch (ServerException $e) {
            $response = $e->getResponse();
        }

        return $response;
    }
900656
public static function get( $url, $params=null, $headers=null, $return_header = false )
	{
		$self = new self();
		if ( is_array($params) ) {
			$params = http_build_query($params);
			if ( strpos($url, '?') == false ) {
				$url .= '?'.$params;
			} else {
				$url .= '&'.$params;
			}
		}

		$curl = $self->_curlInit($url, $headers);
		curl_setopt($curl, CURLOPT_HTTPGET, true);
		return $self->_doRequest($curl, $return_header);
	}
1010385
public function setHeader($header = null)
    {
        if (is_null($header) && $this->getMethod() == "POST") {
            $host = $this->getHost();

            $header = [];
            $header[] = 'POST /cgi-bin/webscr HTTP/1.1';
            $header[] = 'Content-Type: application/x-www-form-urlencoded';
            if (isset($host)) {
                $header[] = 'Host: ' . $host;
            }
            $header[] = 'Connection: close';
        }
        $this->_aHeader = $header;
    }
942328
function urlFor($internalUri, $locale = NULL){
        $internalUri= ltrim($internalUri, '/');
        if($locale == NULL)return $this->request->realBaseUrl . $internalUri;
        else return $this->request->realBaseUrl . $locale . '/' . $internalUri;
    }
463102
public function getHeader($header, $default = null) 
    {
        $name = strtoupper(str_replace('-', '_', $header));
        if (substr($name, 0, 5) != 'HTTP_') {
            $name = 'HTTP_' . $name;
        }
        
        if (($header = $this->getServer($name)) != null) {
            return $header;
        }
        
        return $default;
    }
270851
public function headers($headers = null)
    {
        if (!func_num_args()) {
            return $this->_headers;
        }
        $this->_headers = $headers;
        return $this;
    }
229802
private boolean hasOriginHeader(HttpServletRequest httpReq) {
        String origin = httpReq.getHeader("Origin"); //$NON-NLS-1$
        return origin != null && origin.trim().length() > 0;
    }
108120
public function getHeader($header, $first = true)
    {
        $normalizedHeader = str_replace('-', '_', strtolower($header));
        foreach ($this->headers as $key => $value) {
            if (str_replace('-', '_', strtolower($key)) === $normalizedHeader) {
                if ($first) {
                    return is_array($value) ? (count($value) ? $value[0] : '') : $value;
                }

                return is_array($value) ? $value : array($value);
            }
        }

        return $first ? null : array();
    }
1083142
protected function detectRequestUri()
    {
        $requestUri = null;

        // Check this first so IIS will catch.
        $httpXRewriteUrl = $this->getServer('HTTP_X_REWRITE_URL');
        if ($httpXRewriteUrl !== null) {
            $requestUri = $httpXRewriteUrl;
        }

        // Check for IIS 7.0 or later with ISAPI_Rewrite
        $httpXOriginalUrl = $this->getServer('HTTP_X_ORIGINAL_URL');
        if ($httpXOriginalUrl !== null) {
            $requestUri = $httpXOriginalUrl;
        }

        // IIS7 with URL Rewrite: make sure we get the unencoded url
        // (double slash problem).
        $iisUrlRewritten = $this->getServer('IIS_WasUrlRewritten');
        $unencodedUrl = $this->getServer('UNENCODED_URL', '');
        if ('1' == $iisUrlRewritten && '' !== $unencodedUrl) {
            return $unencodedUrl;
        }

        // HTTP proxy requests setup request URI with scheme and host [and port]
        // + the URL path, only use URL path.
        if (!$httpXRewriteUrl) {
            $requestUri = $this->getServer('REQUEST_URI');
        }

        if ($requestUri !== null) {
            return preg_replace('#^[^/:]+://[^/]+#', '', $requestUri);
        }

        // IIS 5.0, PHP as CGI.
        $origPathInfo = $this->getServer('ORIG_PATH_INFO');
        if ($origPathInfo !== null) {
            $queryString = $this->getServer('QUERY_STRING', '');
            if ($queryString !== '') {
                $origPathInfo .= '?' . $queryString;
            }
            return $origPathInfo;
        }

        return '/';
    }