Return port used for the base URL.
Note, this will be null if not specified, in which case you should assume the default
port for the current protocol.

@param HTTPRequest $request
@return int|null
512171
public static function port(HTTPRequest $request = null)
    {
        $host = static::host($request);
        return (int)parse_url($host, PHP_URL_PORT) ?: null;
    }
734093
public function isCorsRequest(HttpRequest $request)
    {
        $headers = $request->getHeaders();

        if (! $headers->has('Origin')) {
            return false;
        }

        try {
            $origin = $headers->get('Origin');
        } catch (Header\Exception\InvalidArgumentException $exception) {
            throw InvalidOriginException::fromInvalidHeaderValue();
        }

        $originUri  = UriFactory::factory($origin->getFieldValue());
        $requestUri = $request->getUri();

        // According to the spec (http://tools.ietf.org/html/rfc6454#section-4), we should check host, port and scheme

        return (! ($originUri->getHost() === $requestUri->getHost())
            || ! ($originUri->getPort() === $requestUri->getPort())
            || ! ($originUri->getScheme() === $requestUri->getScheme())
        );
    }
1199642
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);
        $details = ArrayObject::ensureArrayObject($request->getModel());

        $httpRequest = new GetHttpRequest();
        $this->gateway->execute($httpRequest);

        if (isset($httpRequest->request['RtnCode']) === true) {
            if ($this->api->verifyHash($httpRequest->request) === false) {
                $httpRequest->request['RtnCode'] = '10400002';
            }
            $details->replace($httpRequest->request);

            return;
        }

        $token = $request->getToken();
        $targetUrl = $token->getTargetUrl();

        if (empty($details['OrderResultURL']) === true) {
            $details['OrderResultURL'] = $targetUrl;
        }

        if (empty($details['ReturnURL']) === true) {
            $notifyToken = $this->tokenFactory->createNotifyToken(
                $token->getGatewayName(), $token->getDetails()
            );
            $details['ReturnURL'] = $notifyToken->getTargetUrl();
        }
        $this->gateway->execute(new CreateTransaction($details));
    }
403480
protected function call($request)
    {
        if(!isset($request['query']))
        {
            $request['query'] = [];
        }

        $method  = 'GET';
        $headers = $this->getHeaders();
        $query   = http_build_query($request['query']);
        $url     = "{$this->domain}/{$request['route']}?$query";

        try {
            $request = $this->getClient()->request($method, $url, [
                'headers' => $headers
            ]);

            $response = $request->getBody()->getContents();

            return json_decode($response, true);

        } catch (RequestException $e) {
            $response = $e->getResponse();
            $response = json_decode($response, true);
            return $response;
        } catch (\Exception $e) {
            return ['error' => $e->getCode(), 'error_description' => $e->getMessage()];
        }
    }
706329
public static function setFromURL(Request $request)
    {
        if(!\Request::route('lang')) {
            // language may be present in url without {param} defined
            $detectLanguageFromRequest = \App\Models\Language::detectLanguageFromRequest($request);
            if ($detectLanguageFromRequest) {
                $request->route()->setParameter('lang', $detectLanguageFromRequest);
                return $detectLanguageFromRequest;
            }
        }
        return null;
    }
240114
protected function getTargetUrl($request)
    {
        $queries = Arr::except($request->query(), ['code', 'state']);

        return $request->url().(empty($queries) ? '' : '?'.http_build_query($queries));
    }
270617
public function getPort() : int
   {

      if ( null !== $this->port )
      {
         return $this->port;
      }

      if ( null === $this->scheme )
      {
         $this->scheme = static::$fallbackScheme;
      }

      switch ( \strtolower( $this->scheme ) )
      {
         case UrlScheme::HTTP : return 80;
         case UrlScheme::SSL  : return 443;
         case UrlScheme::FTP  : return 21;
         default              : return 0;
      }

   }
1320384
public static function getIp(ServerRequestInterface $request)
    {
        $ips = self::getIps($request);

        return isset($ips[0]) ? $ips[0] : null;
    }
1175014
public function defaultPort($port = null)
    {
        if (!is_null($port)) {
            $this->defaultPort = (int)$port;
            if ($this->url['port'] === null) {
                $this->url['port'] = $this->defaultPort;
            }
        }

        return $this->defaultPort;
    }
1164269
protected function getRequestIp($request)
    {
        if ($request->server('HTTP_CF_CONNECTING_IP')) {
            // cloudflare
            return $request->server('HTTP_CF_CONNECTING_IP');
        }

        if ($request->server('X_FORWARDED_FOR')) {
            // forwarded proxy
            return $request->server('X_FORWARDED_FOR');
        }

        if ($request->server('REMOTE_ADDR')) {
            // remote header
            return $request->server('REMOTE_ADDR');
        }
    }
856283
protected function getCallable(Request $request)
    {
        $method = $request->getMethod();
        $uri = $request->getPathInfo();

        return $this->router->getCallable($method, $uri);
    }
18668
public function index(HTTPRequest $request = null)
    {
        $form = $this->Form();
        if ($this->Content && $form && !$this->config()->disable_form_content_shortcode) {
            $hasLocation = stristr($this->Content, '$UserDefinedForm');
            if ($hasLocation) {
                /** @see Requirements_Backend::escapeReplacement */
                $formEscapedForRegex = addcslashes($form->forTemplate(), '\\$');
                $content = preg_replace(
                    '/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i',
                    $formEscapedForRegex,
                    $this->Content
                );
                return [
                    'Content' => DBField::create_field('HTMLText', $content),
                    'Form' => ''
                ];
            }
        }

        return [
            'Content' => DBField::create_field('HTMLText', $this->Content),
            'Form' => $this->Form()
        ];
    }
1051683
protected function detectSubsiteId(HTTPRequest $request)
    {
        if ($request->getVar('SubsiteID') !== null) {
            return (int) $request->getVar('SubsiteID');
        }

        if (SubsiteState::singleton()->getUseSessions() && $request->getSession()->get('SubsiteID') !== null) {
            return (int) $request->getSession()->get('SubsiteID');
        }

        $subsiteIdFromDomain = Subsite::getSubsiteIDForDomain();
        if ($subsiteIdFromDomain !== null) {
            return (int) $subsiteIdFromDomain;
        }

        // Default fallback
        return 0;
    }
584672
@Override
  public int getPort(HttpServletRequest request) {
    String portValue = request.getHeader(X_FORWARED_PORT);
    if( portValue != null ) return Integer.parseInt(portValue);
    return super.getPort(request);
  }
365922
private function preRequest(string $request): string
    {
        $result = $this->preRequest->handle(new TransportContainer($this, $request));

        if ($result instanceof TransportContainer) {
            return $result->getRequest();
        }

        throw new \RuntimeException();
    }
1161808
protected function getOrValidateRequest(HTTPRequest $request = null)
    {
        if ($request instanceof HTTPRequest) {
            return $request;
        }
        if (Injector::inst()->has(HTTPRequest::class)) {
            return Injector::inst()->get(HTTPRequest::class);
        }
        return null;
    }
1329277
public function getIsFrontend(HTTPRequest $request)
    {
        $adminPaths = static::config()->get('admin_url_paths');
        $adminPaths[] = AdminRootController::config()->get('url_base') . '/';
        $currentPath = rtrim($request->getURL(), '/') . '/';

        foreach ($adminPaths as $adminPath) {
            if (substr($currentPath, 0, strlen($adminPath)) === $adminPath) {
                return false;
            }
        }

        // If using the CMS preview, do not treat the site as frontend
        if ($request->getVar('CMSPreview')) {
            return false;
        }

        return true;
    }