Retrieve trusted header name(s), falling back to defaults if config not set.

@return int A bit field of Request::HEADER_*, to set which headers to trust from your proxies.
185663
protected function getTrustedHeaderNames()
    {
        $headers = $this->headers ?: $this->config->get('trustedproxy.headers');
        switch ($headers) {
            case 'HEADER_X_FORWARDED_AWS_ELB':
            case Request::HEADER_X_FORWARDED_AWS_ELB:
                return Request::HEADER_X_FORWARDED_AWS_ELB;
                break;
            case 'HEADER_FORWARDED':
            case Request::HEADER_FORWARDED:
                return Request::HEADER_FORWARDED;
                break;
            default:
                return Request::HEADER_X_FORWARDED_ALL;
        }

        // Should never reach this point
        return $headers;
    }
205650
public static function get_client_ip($trust_proxy_headers = false)
    {
        if (!$trust_proxy_headers) {
            return $_SERVER['REMOTE_ADDR'];
        }

        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        return $ip;
    }
1328142
static public function getClientIp()
    {
        /*
         $headers = function_exists('apache_request_headers')
         ? apache_request_headers()
         : $_SERVER;
         
         return isset($headers['REMOTE_ADDR']) ? $headers['REMOTE_ADDR'] : '0.0.0.0';
         */
        
        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
            $ip = getenv('HTTP_CLIENT_IP');
        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
            $ip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
            $ip = getenv('REMOTE_ADDR');
        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
            $ip = $_SERVER['REMOTE_ADDR'];
        } else {
            return '0.0.0.0';
        }
        
        return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '0.0.0.0';
    }
366712
public static function GetHeaders()
	{
		$headers = false;

		if (function_exists('apache_request_headers')) $headers = apache_request_headers();

		if ($headers === false)
		{
			// apache_request_headers is not supported in this environment

			$headers = array();
			foreach ($_SERVER as $key => $value)
			{
				if (substr($key, 0, 5) <> 'HTTP_')
				{
					continue;
				}
				$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
				$headers[$header] = $value;
			}
		}

		return $headers;
	}
680112
public function getHeader()
    {
        switch ($this->type) {
            case self::TYPE_ERROR:
                $header = 'Error!';
                break;
            case self::TYPE_WARNING:
                $header = 'Warning!';
                break;
            case self::TYPE_INFO:
                $header = 'Info';
                break;
            case self::TYPE_SUCCESS:
                $header = 'Success';
                break;
            default:
                $header = 'Info';
                break;
        }

        return $header;
    }
1132875
public function getHeadersForRequest(): array
    {
        $headers = $this->headers;

        array_walk($headers, function (&$value, $name) {
            $value = "$name: $value";
        });

        return $headers;
    }
150878
private function get_header_url(){
    return "wget -O - --quiet --http-user=" . $this->user . " --http-passwd=" . escapeshellarg($this->pass) . " --no-check-certificate 'https://" . $this->hostname . ":10000/".(
      $this->mode === 'cloudmin' ? 'server-manager' : 'virtual-server'
    )."/remote.cgi?json=1&multiline=&program=";
  }
1295265
protected function _getAuthenticateChallengeHeader()
    {
        $wwwauth = 'Digest realm="' . $this->getRealm() . '", '
            /*
             * Domain directive is not meaningful in Proxy-Authenticate headers,
             * for which the protection space is always the entire proxy; if present
             * it should be ignored.
             */
            . ( ($this->getDomains()) ? 'domain="' . $this->domains . '", ' : '' )
            . 'nonce="' . $this->_generateNonce() . '", '
            /*
             * This can be treated as a session id. If this changes the browser
             * will deauthenticate the user.
             */
            . ( ($this->isUseOpaque()) ? 'opaque="' . $this->_generateOpaque() . '", ' : '' )
            /*
             * indicating that the previous request from the client was
             * rejected because the nonce value was stale. If stale is TRUE
             * (case-insensitive), the client may wish to simply retry the request
             * with a new encrypted response, without reprompting the user for a
             * new username and password. The server should only set stale to TRUE
             * if it receives a request for which the nonce is invalid but with a
             * valid digest for that nonce (indicating that the client knows the
             * correct username/password). If stale is FALSE, or anything other
             * than TRUE, or the stale directive is not present, the username
             * and/or password are invalid, and new values must be obtained.
             */
            . ( (isset($this->stale)) ? 'stale="true"' : '' )
            . 'algorithm="' . $this->defaultAlgorithm . '", '
            . 'qop="' . implode(',', $this->supportedQops) . '"';

        return $wwwauth;
    }
972370
protected function getBasicAuthorizationHeaderInfo()
    {
        $dateTime = new \DateTime();
        $headerParameters = [
            'oauth_callback'         => $this->credentials->getCallbackUrl(),
            'oauth_consumer_key'     => $this->credentials->getConsumerId(),
            'oauth_nonce'            => $this->generateNonce(),
            'oauth_signature_method' => $this->getSignatureMethod(),
            'oauth_timestamp'        => $dateTime->format('U'),
            'oauth_version'          => $this->getVersion(),
        ];

        return $headerParameters;
    }
468888
private function filterHeaders()
    {
        $headers = array();

        foreach ($this->headers as $name => $value) {
            if (strtolower($name) != 'user-agent') {
                $headers[] = "$name: $value";
            }
        }

        return $headers;
    }
102649
public static function getTrustedHeaderName($key)
    {
        if (2 > func_num_args() || func_get_arg(1)) {
            @trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.', __METHOD__), E_USER_DEPRECATED);
        }

        if (!array_key_exists($key, self::$trustedHeaders)) {
            throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
        }

        return self::$trustedHeaders[$key];
    }
559478
public function ensureSentHeaders()
    {
        if ($this->headers_sent) {
            return true;
        }
        if (isset($this->headers['STATUS'])) {
            $h = (isset($this->attrs->noHttpVer) && ($this->attrs->noHttpVer) ? 'Status: ' : $this->attrs->server['SERVER_PROTOCOL']) . ' ' . $this->headers['STATUS'] . "\r\n";
        } else {
            $h = '';
        }
        $http11 = $this->attrs->server['SERVER_PROTOCOL'] === 'HTTP/1.1';
        if ($this->contentLength === null
            && $this->upstream->checkChunkedEncCap()
            && $http11
        ) {
            $this->attrs->chunked = true;
        }
        if ($this->attrs->chunked) {
            $this->header('Transfer-Encoding: chunked');
        }

        if ($http11) {
            $connection = isset($this->attrs->server['HTTP_CONNECTION']) ? strtolower($this->attrs->server['HTTP_CONNECTION']) : 'keep-alive';
            if ($connection === 'keep-alive' && $this->upstream->getKeepaliveTimeout() > 0) {
                $this->header('Connection: keep-alive');
                $this->keepalive = true;
            } else {
                $this->header('Connection: close');
            }
        } else {
            $this->header('Connection: close');
        }

        foreach ($this->headers as $k => $line) {
            if ($k !== 'STATUS') {
                $h .= $line . "\r\n";
            }
        }
        $h .= "\r\n";
        $this->headers_sent_file = __FILE__;
        $this->headers_sent_line = __LINE__;
        $this->headers_sent = true;
        $this->upstream->requestOut($this, $h);
        return false;
    }
1041685
public function getHostName()
    {
        $possibleHostSources = ['HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR'];
        $sourceTransformations = [
            "HTTP_X_FORWARDED_HOST" => function ($value) {
                $elements = explode(',', $value);
                return trim(end($elements));
            },
        ];
        $host = '';
        foreach ($possibleHostSources as $source) {
            if (!empty($host)) {
                break;
            }

            if (empty($_SERVER[$source])) {
                continue;
            }

            $host = $_SERVER[$source];
            if (array_key_exists($source, $sourceTransformations)) {
                $host = $sourceTransformations[$source]($host);
            }
        }

        // Remove port number from host
        $host = preg_replace('/:\d+$/', '', $host);

        return trim($host);
    }
124364
public function getAllowheaders()
    {
        $requestHeaders = $this->request->getAccessControlRequestHeaders();
        if (in_array('*', $this->allowedHeaders) && $requestHeaders) {
            return $requestHeaders;
        }

        return $this->allowedHeaders;
    }
61303
public function getHeaders()
    {
        $defaultHeaders = config('api.defaultHeaders');

        return $defaultHeaders
            ? array_merge($defaultHeaders, $this->headers)
            : $this->headers;
    }
160542
protected function setTrustedProxyIpAddresses(Request $request)
    {
        $trustedIps = $this->proxies ?: $this->config->get('trustedproxy.proxies');

        // Trust any IP address that calls us
        // `**` for backwards compatibility, but is deprecated
        if ($trustedIps === '*' || $trustedIps === '**') {
            return $this->setTrustedProxyIpAddressesToTheCallingIp($request);
        }

        // Support IPs addresses separated by comma
        $trustedIps = is_string($trustedIps) ? array_map('trim', explode(',', $trustedIps)) : $trustedIps;

        // Only trust specific IP addresses
        if (is_array($trustedIps)) {
            return $this->setTrustedProxyIpAddressesToSpecificIps($request, $trustedIps);
        }
    }
1179716
protected function getRequestHeaders()
    {
        $contentKeys = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
        $headers     = array();

        foreach ($this->server as $key => $value) {
            if (strpos($key, 'HTTP_') === 0) {
                $headers[str_replace('_', '-', substr($key, 5))] = $value;
            } elseif (isset($contentKeys[$key])) {
                $headers[str_replace('_', '-', $key)] = $value;
            }
        }

        if (!isset($headers['AUTHORIZATION'])) {
            if (isset($this->server['REDIRECT_HTTP_AUTHORIZATION'])) {
                $headers['AUTHORIZATION'] = $this->server['REDIRECT_HTTP_AUTHORIZATION'];
            } elseif (isset($this->server['PHP_AUTH_USER'])) {
                $headers['AUTHORIZATION'] = 'Basic ' . base64_encode($this->server['PHP_AUTH_USER'] . ':' . (isset($this->server['PHP_AUTH_PW']) ? $this->server['PHP_AUTH_PW'] : ''));
            } elseif (isset($this->server['PHP_AUTH_DIGEST'])) {
                $headers['AUTHORIZATION'] = $this->server['PHP_AUTH_DIGEST'];
            }
        }

        return $headers;
    }