getSchemeAndHttpHost example

unset($params[$key]);
            }
        }
        ksort($params);
        $params = http_build_query($params);

        $baseUrl = $request->attributes->get(RequestTransformer::SALES_CHANNEL_BASE_URL) ?? '';
        \assert(\is_string($baseUrl));

        return sprintf(
            '%s%s%s%s',
            $request->getSchemeAndHttpHost(),
            $baseUrl,
            $request->getPathInfo(),
            '?' . $params
        );
    }
}

  protected function getCacheId(Request $request) {
    // Once a cache ID is determined for the request, reuse it for the duration     // of the request. This ensures that when the cache is written, it is only     // keyed on request data that was available when it was read. For example,     // the request format might be NULL during cache lookup and then set during     // routing, in which case we want to key on NULL during writing, since that     // will be the value during lookups for subsequent requests.     if (!isset($this->cid)) {
      $cid_parts = [
        $request->getSchemeAndHttpHost() . $request->getRequestUri(),
        $request->getRequestFormat(NULL),
      ];
      $this->cid = implode(':', $cid_parts);
    }
    return $this->cid;
  }

}
if (!$response->headers->has('Vary')) {
            $response->headers->set('Vary', $header);
        } elseif (!in_array($headerexplode(', ', $response->headers->get('Vary')))) {
            $response->headers->set('Vary', $response->headers->get('Vary') . ', ' . $header);
        }

        return $response;
    }

    private function isSameHost(Request $request): bool
    {
        return $request->headers->get('Origin') === $request->getSchemeAndHttpHost();
    }
}

  protected static function getRequestLink(Request $request$query = NULL) {
    if ($query === NULL) {
      return Url::fromUri($request->getUri());
    }

    $uri_without_query_string = $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo();
    return Url::fromUri($uri_without_query_string)->setOption('query', $query);
  }

  /** * Get the pager links for a given request object. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * @param \Drupal\jsonapi\Query\OffsetPage $page_param * The current pagination parameter for the requested collection. * @param array $link_context * An associative array with extra data to build the links. * * @return \Drupal\jsonapi\JsonApiResource\LinkCollection * A LinkCollection, with: * - a 'next' key if it is not the last page; * - 'prev' and 'first' keys if it's not the first page. */
// Invoke hook_mail_alter() to allow all modules to alter the resulting     // email.     $this->moduleHandler->alter('mail', $message);

    // Retrieve the responsible implementation for this message.     $system = $this->getInstance(['module' => $module, 'key' => $key]);

    // Attempt to convert relative URLs to absolute.     foreach ($message['body'] as &$body_part) {
      if ($body_part instanceof MarkupInterface) {
        $body_part = Markup::create(Html::transformRootRelativeUrlsToAbsolute((string) $body_part, \Drupal::request()->getSchemeAndHttpHost()));
      }
    }

    // Format the message body.     $message = $system->format($message);

    // Optionally send email.     if ($send) {
      // The original caller requested sending. Sending was canceled by one or       // more hook_mail_alter() implementations. We set 'result' to NULL,       // because FALSE indicates an error in sending.
$path = $this->fragmentPath.'?'.http_build_query($controller->query, '', '&');

        // we need to sign the absolute URI, but want to return the path only.         $fragmentUri = $sign || $absolute ? $request->getUriForPath($path) : $request->getBaseUrl().$path;

        if (!$sign) {
            return $fragmentUri;
        }

        $fragmentUri = $this->signer->sign($fragmentUri);

        return $absolute ? $fragmentUri : substr($fragmentUri, \strlen($request->getSchemeAndHttpHost()));
    }

    private function checkNonScalar(array $values): void
    {
        foreach ($values as $key => $value) {
            if (\is_array($value)) {
                $this->checkNonScalar($value);
            } elseif (!\is_scalar($value) && null !== $value) {
                throw new \LogicException(sprintf('Controller attributes cannot contain non-scalar/non-null values (value for key "%s" is not a scalar or null).', $key));
            }
        }
    }
$orgRequest->server->set('SERVER_NAME', 'localhost');
        $orgRequest->server->set('SERVER_PORT', '443');

        static::assertTrue($orgRequest->isSecure());

        $appVariable = $this->createMock(AppVariable::class);
        $appVariable->method('getRequest')->willReturn($orgRequest);

        $app = new TwigAppVariable($appVariable$this->getContainer()->getParameter('shopware.twig.app_variable.allowed_server_params'));

        static::assertTrue($app->getRequest()->isSecure());
        static::assertSame('https://localhost', $app->getRequest()->getSchemeAndHttpHost());
    }
}
/** * Generates a normalized URI (URL) for the Request. * * @see getQueryString() */
    public function getUri(): string
    {
        if (null !== $qs = $this->getQueryString()) {
            $qs = '?'.$qs;
        }

        return $this->getSchemeAndHttpHost().$this->getBaseUrl().$this->getPathInfo().$qs;
    }

    /** * Generates a normalized URI for the given path. * * @param string $path A path to use instead of the current one */
    public function getUriForPath(string $path): string
    {
        return $this->getSchemeAndHttpHost().$this->getBaseUrl().$path;
    }

    
private function getFileLinkFormat(): array|false
    {
        if ($this->fileLinkFormat) {
            return $this->fileLinkFormat;
        }

        if ($this->requestStack && $this->baseDir && $this->urlFormat) {
            $request = $this->requestStack->getMainRequest();

            if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || $this->urlFormat = ($this->urlFormat)())) {
                return [
                    $request->getSchemeAndHttpHost().$this->urlFormat,
                    $this->baseDir.\DIRECTORY_SEPARATOR, '',
                ];
            }
        }

        return false;
    }
}
/** * Tests form action attribute for XSS. */
  public function testFormActionXss() {
    // Create a new request with a uri which attempts XSS.     $request_stack = \Drupal::service('request_stack');
    /** @var \Symfony\Component\HttpFoundation\RequestStack $original_request */
    $original_request = $request_stack->pop();
    // Just request some more so there is no request left.     $request_stack->pop();
    $request_stack->pop();
    $request = Request::create($original_request->getSchemeAndHttpHost() . '/test/"injected=\'attribute\'close="');
    $request_stack->push($request);

    $form = \Drupal::formBuilder()->getForm($this);
    $markup = \Drupal::service('renderer')->renderRoot($form);
    $this->setRawContent($markup);

    $elements = $this->xpath('//form');
    $action = isset($elements[0]['action']) ? (string) $elements[0]['action'] : FALSE;
    $injected = isset($elements[0]['injected']) ? (string) $elements[0]['injected'] : FALSE;

    $this->assertSame('/test/"injected=\'attribute\'close="', $action);
    
private function getFileLinkFormat(): array|false
    {
        if ($this->fileLinkFormat) {
            return $this->fileLinkFormat;
        }

        if ($this->requestStack && $this->baseDir && $this->urlFormat) {
            $request = $this->requestStack->getMainRequest();

            if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || $this->urlFormat = ($this->urlFormat)())) {
                return [
                    $request->getSchemeAndHttpHost().$this->urlFormat,
                    $this->baseDir.\DIRECTORY_SEPARATOR, '',
                ];
            }
        }

        return false;
    }
}


  /** * Checks that relative paths in mails are converted into absolute URLs. */
  public function testConvertRelativeUrlsIntoAbsolute() {
    $language_interface = \Drupal::languageManager()->getCurrentLanguage();

    $this->configureDefaultMailInterface('test_html_mail_collector');

    // Fetch the hostname and port for matching against.     $http_host = \Drupal::request()->getSchemeAndHttpHost();

    // Random generator.     $random = new Random();

    // One random tag name.     $tag_name = strtolower($random->name(8, TRUE));

    // Test root relative URLs.     foreach (['href', 'src'] as $attribute) {
      // Reset the state variable that holds sent messages.       \Drupal::state()->set('system.test_mail_collector', []);

      


        $this->serverRequestFactory = $serverRequestFactory;
        $this->streamFactory = $streamFactory;
        $this->uploadedFileFactory = $uploadedFileFactory;
        $this->responseFactory = $responseFactory;
    }

    public function createRequest(Request $symfonyRequest): ServerRequestInterface
    {
        $uri = $symfonyRequest->server->get('QUERY_STRING', '');
        $uri = $symfonyRequest->getSchemeAndHttpHost().$symfonyRequest->getBaseUrl().$symfonyRequest->getPathInfo().('' !== $uri ? '?'.$uri : '');

        $request = $this->serverRequestFactory->createServerRequest(
            $symfonyRequest->getMethod(),
            $uri,
            $symfonyRequest->server->all()
        );

        foreach ($symfonyRequest->headers->all() as $name => $value) {
            try {
                $request = $request->withHeader($name$value);
            } catch (\InvalidArgumentException $e) {
                
      $uri = $this->pathProcessor->processOutbound($uri$options, NULL, $generated_url);
    }
    // Strip leading slashes from internal paths to prevent them becoming     // external URLs without protocol. /example.com should not be turned into     // //example.com.     $uri = ltrim($uri, '/');

    // Add any subdirectory where Drupal is installed.     $current_base_path = $request->getBasePath() . '/';

    if ($options['absolute']) {
      $current_base_url = $request->getSchemeAndHttpHost() . $current_base_path;
      if (isset($options['https'])) {
        if (!empty($options['https'])) {
          $base = str_replace('http://', 'https://', $current_base_url);
          $options['absolute'] = TRUE;
        }
        else {
          $base = str_replace('https://', 'http://', $current_base_url);
          $options['absolute'] = TRUE;
        }
      }
      else {
        

  protected function initializeRequestGlobals(Request $request) {
    global $base_url;
    // Set and derived from $base_url by this function.     global $base_path$base_root;
    global $base_secure_url$base_insecure_url;

    // Create base URL.     $base_root = $request->getSchemeAndHttpHost();
    $base_url = $base_root;

    // For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is     // '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.     if ($dir = rtrim(dirname($request->server->get('SCRIPT_NAME')), '\/')) {
      // Remove "core" directory if present, allowing install.php,       // authorize.php, and others to auto-detect a base path.       $core_position = strrpos($dir, '/core');
      if ($core_position !== FALSE && strlen($dir) - 5 == $core_position) {
        $base_path = substr($dir, 0, $core_position);
      }
      
Home | Imprint | This part of the site doesn't use cookies.