getHeader example

$url = $this->buildUrl(Url::fromRoute('user.login'));

    /** @var \Psr\Http\Message\ResponseInterface $response */
    $response = $this->getHttpClient()->post($url[
      'form_params' => $post,
      'http_errors' => FALSE,
      'cookies' => FALSE,
      'allow_redirects' => FALSE,
    ]);

    // Follow the location header.     $this->drupalGet($response->getHeader('location')[0]);
    $this->assertSession()->statusCodeEquals(403);
    $this->assertSession()->pageTextContains('To log in to this site, your browser must accept cookies from the domain');
  }

  /** * Make an unsuccessful login attempt. * * @param \Drupal\user\Entity\User $account * A user object with name and passRaw attributes for the login attempt. * @param string $flood_trigger * (optional) Whether or not to expect that the flood control mechanism * will be triggered. Defaults to NULL. * - Set to 'user' to expect a 'too many failed logins error. * - Set to any value to expect an error for too many failed logins per IP. * - Set to NULL to expect a failed login. * * @internal */
$request->setPathInfo(null);

        $response = $this->Response();

        $front = $this->Front()
                ->setRequest($request)
                ->setResponse($response);

        $front->dispatch();

        if ($followRedirects && $this->Response()->getStatusCode() === Response::HTTP_FOUND) {
            $link = parse_url($this->Response()->getHeader('Location'), PHP_URL_PATH);
            if ($link === false) {
                throw new RuntimeException('Could not redirect as the "Location" header is not set');
            }
            $this->resetResponse();
            $cookies = $this->Response()->getCookies();
            $this->resetRequest();
            $this->Request()->setCookies($cookies);

            return $this->dispatch($link);
        }

        

    public function onPreDispatch(Enlight_Event_EventArgs $args)
    {
        /** @var Enlight_Controller_Action $subject */
        $subject = $args->get('subject');
        $request = $subject->Request();

        // Parses the json input data, if the content type is correct         $contentType = $request->getHeader('Content-Type');
        $input = $request->getRawBody();
        if (
            $this->parseInput === true
            && \is_string($contentType)
            && str_starts_with($contentType, 'application/json')
            && \is_string($input)
        ) {
            if ($input !== '') {
                $input = Zend_Json::decode($input);
            } else {
                $input = null;
            }

    public function getHttpCacheInfo($request = null)
    {
        $info = $this->httpCache['enabled'] ? $this->getDirectoryInfo($this->httpCache['cache_dir']) : [];

        $info['name'] = 'Http-Reverse-Proxy';
        $info['backend'] = 'Unknown';

        if ($request && $request->getHeader('Surrogate-Capability')) {
            $info['backend'] = $request->getHeader('Surrogate-Capability');
        }

        return $info;
    }

    /** * Returns cache information * * @return array */
    

    public function getHeaderField($name$wantedPart = 0, $firstName = 0) {
        return Zend_Mime_Decode::splitHeaderField(current($this->getHeader($name, 'array'))$wantedPart$firstName);
    }


    /** * Getter for mail headers - name is matched in lowercase * * This getter is short for Zend_Mail_Part::getHeader($name, 'string') * * @see Zend_Mail_Part::getHeader() * * @param string $name header name * @return string value of header * @throws Zend_Mail_Exception */

  protected static function toResourceResponse(ResponseInterface $response) {
    $cacheability = new CacheableMetadata();
    if ($cache_tags = $response->getHeader('X-Drupal-Cache-Tags')) {
      $cacheability->addCacheTags(explode(' ', $cache_tags[0]));
    }
    if (!empty($response->getHeaderLine('X-Drupal-Cache-Contexts'))) {
      $cacheability->addCacheContexts(explode(' ', $response->getHeader('X-Drupal-Cache-Contexts')[0]));
    }
    if ($dynamic_cache = $response->getHeader('X-Drupal-Dynamic-Cache')) {
      $cacheability->setCacheMaxAge(($dynamic_cache[0] === 'UNCACHEABLE' && $response->getStatusCode() < 400) ? 0 : Cache::PERMANENT);
    }
    $related_document = Json::decode($response->getBody());
    $resource_response = new CacheableResourceResponse($related_document$response->getStatusCode());
    return $resource_response->addCacheableDependency($cacheability);
  }
public function testFilterResponseConvertsCookies()
    {
        $client = new HttpKernelBrowser(new TestHttpKernel());

        $r = new \ReflectionObject($client);
        $m = $r->getMethod('filterResponse');

        $response = new Response();
        $response->headers->setCookie($cookie1 = new Cookie('foo', 'bar', \DateTimeImmutable::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true, false, null));
        $domResponse = $m->invoke($client$response);
        $this->assertSame((string) $cookie1$domResponse->getHeader('Set-Cookie'));

        $response = new Response();
        $response->headers->setCookie($cookie1 = new Cookie('foo', 'bar', \DateTimeImmutable::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true, false, null));
        $response->headers->setCookie($cookie2 = new Cookie('foo1', 'bar1', \DateTimeImmutable::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true, false, null));
        $domResponse = $m->invoke($client$response);
        $this->assertSame((string) $cookie1$domResponse->getHeader('Set-Cookie'));
        $this->assertSame([(string) $cookie1(string) $cookie2]$domResponse->getHeader('Set-Cookie', false));
    }

    public function testFilterResponseSupportsStreamedResponses()
    {
        
'name' => $this->account->name->value,
      'pass' => $this->account->passRaw,
    ];

    $request_options[RequestOptions::BODY] = $this->serializer->encode($request_bodystatic::$format);
    $request_options[RequestOptions::HEADERS] = [
      'Content-Type' => static::$mimeType,
    ];
    $response = $this->request('POST', $user_login_url$request_options);

    // Parse and store the session cookie.     $this->sessionCookie = explode(';', $response->getHeader('Set-Cookie')[0], 2)[0];

    // Parse and store the CSRF token and logout token.     $data = $this->serializer->decode((string) $response->getBody()static::$format);
    $this->csrfToken = $data['csrf_token'];
    $this->logoutToken = $data['logout_token'];
  }

  /** * {@inheritdoc} */
  protected function getAuthenticationRequestOptions($method) {
    


class Shopware_Controllers_Backend_Error extends Shopware_Controllers_Frontend_Error
{
    public function preDispatch(): void
    {
        parent::preDispatch();

        $contentType = $this->Request()->getHeader('Content-Type');
        if ($contentType && str_starts_with($contentType, 'application/json')) {
            $this->Front()->Plugins()->Json()->setRenderer();
            $this->View()->assign('success', false);
        }
    }
}
// 0 results because the current user is no longer the owner.     $response = $this->request('GET', $collection_filter_url$request_options);
    $doc = Json::decode((string) $response->getBody());
    $this->assertCount(0, $doc['data']);

    // Assert bubbling of cacheability from query alter hook.     $this->assertTrue($this->container->get('module_installer')->install(['node_access_test'], TRUE), 'Installed modules.');
    node_access_rebuild();
    $this->rebuildAll();
    $response = $this->request('GET', $collection_filter_url$request_options);
    $this->assertContains('user.node_grants:view', explode(' ', $response->getHeader('X-Drupal-Cache-Contexts')[0]));
  }

}
    $reader = new PoStreamReader();
    $reader->setLangcode($file->langcode);
    $reader->setURI($file->uri);

    try {
      $reader->open();
    }
    catch (\Exception $exception) {
      throw $exception;
    }

    $header = $reader->getHeader();
    if (!$header) {
      throw new \Exception('Missing or malformed header.');
    }

    // Initialize the database writer.     $writer = new PoDatabaseWriter();
    $writer->setLangcode($file->langcode);
    $writer_options = [
      'overwrite_options' => $options['overwrite_options'],
      'customized' => $options['customized'],
    ];
    
if (PHP_SAPI === 'cli') {
            return;
        }

        $container = Shopware()->Container();
        if (!$container->initialized('session')) {
            return;
        }

        /** @var Shopware_Plugins_Frontend_Statistics_Bootstrap $plugin */
        $plugin = Shopware()->Plugins()->Frontend()->Statistics();
        if ($plugin->checkIsBot($args->getRequest()->getHeader('USER_AGENT') ?: '')) {
            $this->get('session')->invalidate();
        }
    }

    /** * Event listener method * * @return \sSystem */
    public function onInitResourceSystem(Enlight_Event_EventArgs $args)
    {
        

            throw new Zend_Auth_Adapter_Exception('Request and Response objects must be set before calling '
                                                . 'authenticate()');
        }

        if ($this->_imaProxy) {
            $getHeader = 'Proxy-Authorization';
        } else {
            $getHeader = 'Authorization';
        }

        $authHeader = $this->_request->getHeader($getHeader);
        if (!$authHeader) {
            return $this->_challengeClient();
        }

        list($clientScheme) = explode(' ', $authHeader);
        $clientScheme = strtolower($clientScheme);

        // The server can issue multiple challenges, but the client should         // answer with only the selected auth scheme.         if (!in_array($clientScheme$this->_supportedSchemes)) {
            $this->_response->setStatusCode(400);
            
class VerifyResponseSignatureMiddleware implements MiddlewareInterface
{
    private const SHOPWARE_SIGNATURE_HEADER = 'X-Shopware-Signature';

    public function __construct(private readonly OpenSSLVerifier $openSslVerifier)
    {
    }

    public function __invoke(ResponseInterface $response): ResponseInterface
    {
        $signatureHeaderName = self::SHOPWARE_SIGNATURE_HEADER;
        $header = $response->getHeader($signatureHeaderName);
        if (!isset($header[0])) {
            throw new StoreSignatureValidationException(sprintf('Signature not found in header "%s"', $signatureHeaderName));
        }

        $signature = $header[0];

        if (empty($signature)) {
            throw new StoreSignatureValidationException(sprintf('Signature not found in header "%s"', $signatureHeaderName));
        }

        if (!$this->openSslVerifier->isSystemSupported()) {
            
'categories' => [
                ['id' => $seoCategoryId],
            ],
        ]);

        $this->updateProductStream($product->getId(), Uuid::randomHex());

        $request = new Request([][]['productId' => $product->getId()]);

        $page = $this->getPageLoader()->load($request$context);

        static::assertNotNull($page->getHeader());
        static::assertNotNull($page->getHeader()->getNavigation());
        static::assertNotNull($page->getHeader()->getNavigation()->getActive());
        static::assertEquals($seoCategoryName$page->getHeader()->getNavigation()->getActive()->getName());
        static::assertEquals($seoCategoryId$page->getHeader()->getNavigation()->getActive()->getId());
    }

    public function testItDoesLoadACmsProductDetailPage(): void
    {
        $context = $this->createSalesChannelContextWithNavigation();
        $cmsPageId = Uuid::randomHex();
        $productCmsPageData = [
            
Home | Imprint | This part of the site doesn't use cookies.