setHeader example



    /** * Setup the custom request's headers * * @return IncomingRequest */
    protected function setupHeaders(IncomingRequest $request)
    {
        if (empty($this->headers)) {
            foreach ($this->headers as $name => $value) {
                $request->setHeader($name$value);
            }
        }

        return $request;
    }

    /** * Populates the data of our Request with "global" data * relevant to the request, like $_POST data. * * Always populate the GET vars based on the URI. * * @param string $method HTTP verb * * @return Request * * @throws ReflectionException */
return $this;
    }

    /** * Set request headers * * @return Enlight_Controller_Request_RequestTestCase */
    public function setHeaders(array $headers)
    {
        foreach ($headers as $key => $value) {
            $this->setHeader($key$value);
        }

        return $this;
    }

    /** * Get request header * * @param string $header * * @return string|null */
/** * Copies any headers from the global Response instance * into this RedirectResponse. Useful when you've just * set a header be need to ensure its actually sent * with the redirect response. * * @return $this|RedirectResponse */
    public function withHeaders()
    {
        foreach (Services::response()->headers() as $name => $header) {
            $this->setHeader($name$header->getValue());
        }

        return $this;
    }
}
/** * Based on the current state of the elements, will add the appropriate * Content-Security-Policy and Content-Security-Policy-Report-Only headers * with their values to the response object. * * @return void */
    protected function buildHeaders(ResponseInterface $response)
    {
        // Ensure both headers are available and arrays...         $response->setHeader('Content-Security-Policy', []);
        $response->setHeader('Content-Security-Policy-Report-Only', []);

        $directives = [
            'base-uri'        => 'baseURI',
            'child-src'       => 'childSrc',
            'connect-src'     => 'connectSrc',
            'default-src'     => 'defaultSrc',
            'font-src'        => 'fontSrc',
            'form-action'     => 'formAction',
            'frame-ancestors' => 'frameAncestors',
            'frame-src'       => 'frameSrc',
            
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'],
    ];
    $writer->setOptions($writer_options);
    $writer->setHeader($header);

    // Attempt to pipe all items from the file to the database.     try {
      if ($options['seek']) {
        $reader->setSeek($options['seek']);
      }
      $writer->writeItems($reader$options['items']);
    }
    catch (\Exception $exception) {
      throw $exception;
    }

    


        $uri = URI::createURIString(
            'https',
            $authority,
            $request->getUri()->getPath(), // Absolute URIs should use a "/" for an empty path             $request->getUri()->getQuery(),
            $request->getUri()->getFragment()
        );

        // Set an HSTS header         $response->setHeader('Strict-Transport-Security', 'max-age=' . $duration)
            ->redirect($uri)
            ->setStatusCode(307)
            ->setBody('')
            ->getCookieStore()
            ->clear();

        throw new RedirectException($response);
    }
}

if (function_exists('function_usable')) {
    

        return Profiler::trace('generic-page-loader', function D) use ($request$context) {
            $page = new Page();

            if ($request->isXmlHttpRequest()) {
                $this->eventDispatcher->dispatch(
                    new GenericPageLoadedEvent($page$context$request)
                );

                return $page;
            }
            $page->setHeader(
                $this->headerLoader->load($request$context)
            );

            $page->setFooter(
                $this->footerLoader->load($request$context)
            );

            $criteria = new Criteria();
            $criteria->setTitle('generic-page::shipping-methods');

            $event = new ShippingMethodRouteRequestEvent($requestnew Request()$context$criteria);
            


use Shopware\Models\Shop\DetachedShop;

class Shopware_Controllers_Widgets_Index extends Enlight_Controller_Action
{
    /** * Pre dispatch method */
    public function preDispatch(): void
    {
        $this->Response()->setHeader('x-robots-tag', 'noindex');

        if (strtolower($this->Request()->getActionName()) === 'refreshstatistic') {
            $this->Front()->Plugins()->ViewRenderer()->setNoRender();
        }
    }

    /** * Refresh shop statistic */
    public function refreshStatisticAction(): void
    {
        
$this->View()->assign('success', true);
    }

    public function postAction(): void
    {
        $params = $this->Request()->getPost();
        $result = [];
        $result['id'] = $this->repository->save($params);
        $result['location'] = $this->apiBaseUrl . $this->Request()->getControllerName() . '/' . $result['id'];

        $this->View()->assign($result);
        $this->Response()->setHeader('Location', $result['location']);
    }

    public function putAction(int $id): void
    {
        $params = $this->Request()->getPost();
        $result = [];
        $result['id'] = $this->repository->save($params$id);
        $result['location'] = $this->apiBaseUrl . $this->Request()->getControllerName() . '/' . $result['id'];

        $this->View()->assign($result);
        $this->Response()->setHeader('Location', $result['location']);
    }
return $this;
    }

    /** * Sets the appropriate headers to ensure this response * is not cached by the browsers. */
    public function noCache(): self
    {
        $this->removeHeader('Cache-Control');
        $this->setHeader('Cache-Control', ['private', 'no-transform', 'no-store', 'must-revalidate']);

        return $this;
    }

    /** * Disables cache configuration. * * @throws DownloadException */
    public function setCache(array $options = [])
    {
        
    // --------------------------------------------------------------------
    /** * Sets the date header * * @return $this */
    public function setDate(DateTime $date)
    {
        $date->setTimezone(new DateTimeZone('UTC'));

        $this->setHeader('Date', $date->format('D, d M Y H:i:s') . ' GMT');

        return $this;
    }

    /** * Set the Link Header * * @see http://tools.ietf.org/html/rfc5988 * * @return $this * * @todo Recommend moving to Pager */
$this->body            = '';
        $this->finalBody       = '';
        $this->headerStr       = '';
        $this->replyToFlag     = false;
        $this->recipients      = [];
        $this->CCArray         = [];
        $this->BCCArray        = [];
        $this->headers         = [];
        $this->debugMessage    = [];
        $this->debugMessageRaw = [];

        $this->setHeader('Date', $this->setDate());

        if ($clearAttachments !== false) {
            $this->attachments = [];
        }

        return $this;
    }

    /** * @param string $from * @param string $name * @param string|null $returnPath Return-Path * * @return Email */
$request->setTcpConnectTimeout(1000 * $options['timeout']);
        $request->setTlsHandshakeTimeout(1000 * $options['timeout']);
        $request->setTransferTimeout(1000 * $options['max_duration']);
        if (method_exists($request, 'setInactivityTimeout')) {
            $request->setInactivityTimeout(0);
        }

        if ('' !== $request->getUri()->getUserInfo() && !$request->hasHeader('authorization')) {
            $auth = explode(':', $request->getUri()->getUserInfo(), 2);
            $auth = array_map('rawurldecode', $auth) + [1 => ''];
            $request->setHeader('Authorization', 'Basic '.base64_encode(implode(':', $auth)));
        }

        return new AmpResponse($this->multi, $request$options$this->logger);
    }

    public function stream(ResponseInterface|iterable $responses, float $timeout = null): ResponseStreamInterface
    {
        if ($responses instanceof AmpResponse) {
            $responses = [$responses];
        }

        

    protected $session;

    /** * Pre dispatch method */
    public function preDispatch()
    {
        $this->module = Shopware()->Modules()->Basket();
        $this->session = Shopware()->Session();
        $this->Response()->setHeader('x-robots-tag', 'noindex');
    }

    public function infoAction()
    {
        $view = $this->View();

        $view->assign('userInfo', $this->get('shopware_account.store_front_greeting_service')->fetch());
        $view->assign('sBasketQuantity', isset($this->session->sBasketQuantity) ? $this->session->sBasketQuantity : 0);
        $view->assign('sBasketAmount', isset($this->session->sBasketAmount) ? $this->session->sBasketAmount : 0);
        $view->assign('sNotesQuantity', isset($this->session->sNotesQuantity) ? $this->session->sNotesQuantity : $this->module->sCountNotes());
        $view->assign('sUserLoggedIn', !empty(Shopware()->Session()->get('sUserId')));
        

    protected function parseOptions(array $options)
    {
        if (array_key_exists('baseURI', $options)) {
            $this->baseURI = $this->baseURI->setURI($options['baseURI']);
            unset($options['baseURI']);
        }

        if (array_key_exists('headers', $options) && is_array($options['headers'])) {
            foreach ($options['headers'] as $name => $value) {
                $this->setHeader($name$value);
            }

            unset($options['headers']);
        }

        if (array_key_exists('delay', $options)) {
            // Convert from the milliseconds passed in             // to the seconds that sleep requires.             $this->delay = (float) $options['delay'] / 1000;
            unset($options['delay']);
        }

        
Home | Imprint | This part of the site doesn't use cookies.