sendHeaders example


    public function send()
    {
        // Turn off output buffering completely, even if php.ini output_buffering is not off         if (ENVIRONMENT !== 'testing') {
            while (ob_get_level() > 0) {
                ob_end_clean();
            }
        }

        $this->buildHeaders();
        $this->sendHeaders();
        $this->sendBody();

        return $this;
    }

    /** * set header for file download. * * @return void */
    public function buildHeaders()
    {

use Symfony\Component\HttpFoundation\Cookie;

$r = require __DIR__.'/common.inc';

$str1 = "=,; \t\r\n\v\f";
$r->headers->setCookie(new Cookie($str1$str1, 0, '', null, false, false, false, null));

$str2 = '?*():@&+$/%#[]';

$r->headers->setCookie(new Cookie($str2$str2, 0, '', null, false, false, false, null));
$r->sendHeaders();

setcookie($str2$str2, 0, '/');
$this->export = Shopware()->Modules()->Export();
    }

    /** * Index action method * * Creates the export product. */
    public function indexAction()
    {
        $this->prepareExport();
        $this->sendHeaders();

        $productFeed = $this->get('models')->getRepository('\Shopware\Models\ProductFeed\ProductFeed')->find((int) $this->Request()->feedID);

        // Live generation         if ($productFeed->getInterval() === 0) {
            $this->generateExport('php://output');

            return;
        }

        $directory = $this->createOutputDirectory();
        
return $this;
    }

    /** * Sends HTTP headers and content. * * @return $this */
    public function send()static
    {
        $this->sendHeaders();
        $this->sendContent();

        if (\function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        } elseif (\function_exists('litespeed_finish_request')) {
            litespeed_finish_request();
        } elseif (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
            static::closeOutputBuffers(0, true);
            flush();
        }

        


            return;
        }

        @set_time_limit(0);

        $response->headers->set('content-type', $mimeType);
        $response->headers->set('content-disposition', sprintf('attachment; filename="%s"', basename($location)));
        $response->headers->set('content-length', $meta['size']);
        $response->headers->set('content-transfer-encoding', 'binary');
        $response->sendHeaders();

        $upstream = $filesystem->readStream($location);
        if (!\is_resource($upstream)) {
            throw new RuntimeException(sprintf('Could not read stream from: %s', $location));
        }
        $downstream = fopen('php://output', 'wb');
        if (!\is_resource($downstream)) {
            throw new RuntimeException('Could not create temp stream');
        }

        if (!$this->unitTestMode) {
            
<?php
use Symfony\Component\HttpFoundation\Cookie;

$r = require __DIR__.'/common.inc';

$r->headers->setCookie(new Cookie('CookieSamesiteStrictTest', 'StrictValue', 0, '/', null, false, true, false, Cookie::SAMESITE_STRICT));
$r->sendHeaders();
<?php
use Symfony\Component\HttpFoundation\Cookie;

$r = require __DIR__.'/common.inc';

$r->headers->setCookie(new Cookie('CookieSamesiteLaxTest', 'LaxValue', 0, '/', null, false, true, false, Cookie::SAMESITE_LAX));
$r->sendHeaders();
<?php
use Symfony\Component\HttpFoundation\Cookie;

$r = require __DIR__.'/common.inc';

$str = '?*():@&+$/%#[]';

$r->headers->setCookie(new Cookie($str$str, 0, '/', null, false, false, true, null));
$r->sendHeaders();

setrawcookie($str$str, 0, '/', '', false, false);
$mimeType = $filesystem->getMimetype($path) ?: 'application/octet-stream';

        @set_time_limit(0);

        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        $response = $this->Response();
        $response->headers->set('content-type', $mimeType);
        $response->headers->set('content-disposition', sprintf('attachment; filename="%s"', basename($path)));
        $response->headers->set('content-length', $meta['size']);
        $response->headers->set('content-transfer-encoding', 'binary');
        $response->sendHeaders();
        $response->sendResponse();

        $upstream = $filesystem->readStream($path);
        if (!\is_resource($upstream)) {
            throw new RuntimeException(sprintf('Could not open file from: %s', $path));
        }
        $downstream = fopen('php://output', 'wb');
        if (!\is_resource($downstream)) {
            throw new RuntimeException('Could not open temporary stream');
        }

        
$populatedLinks = [];
        foreach ($links as $link) {
            if ($link instanceof EvolvableLinkInterface && !$link->getRels()) {
                $link = $link->withRel('preload');
            }

            $populatedLinks[] = $link;
        }

        $response->headers->set('Link', $this->container->get('web_link.http_header_serializer')->serialize($populatedLinks), false);
        $response->sendHeaders(103);

        return $response;
    }

    private function doRenderView(string $view, ?string $block, array $parameters, string $method): string
    {
        if (!$this->container->has('twig')) {
            throw new \LogicException(sprintf('You cannot use the "%s" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".', $method));
        }

        foreach ($parameters as $k => $v) {
            


        $logFilePath = $logDir . '/' . $this->getLogFile($files$logFile);

        $response = $this->Response();
        $response->headers->set('cache-control', 'public', true);
        $response->headers->set('content-type', 'application/octet-stream');
        $response->headers->set('content-description', 'File Transfer');
        $response->headers->set('content-disposition', 'attachment; filename=' . $logFile);
        $response->headers->set('content-transfer-encoding', 'binary');
        $response->headers->set('content-length', (string) filesize($logFilePath));
        $response->sendHeaders();

        $this->Front()->Plugins()->ViewRenderer()->setNoRender();

        $out = fopen('php://output', 'wb');
        if (!\is_resource($out)) {
            throw new RuntimeException('Could not open temporary stream');
        }
        $file = fopen($logFilePath, 'rb');
        if (!\is_resource($file)) {
            throw new RuntimeException('Could not open log file');
        }

        
public function sendHeaders(/* int $statusCode = null */)static
    {
        if ($this->headersSent) {
            return $this;
        }

        $statusCode = \func_num_args() > 0 ? func_get_arg(0) : null;
        if ($statusCode < 100 || $statusCode >= 200) {
            $this->headersSent = true;
        }

        return parent::sendHeaders($statusCode);
    }

    /** * This method only sends the content once. * * @return $this */
    public function sendContent()static
    {
        if ($this->streamed) {
            return $this;
        }
$this->requestStack->push($request);
        }

        try {
            $response = $this->handleThrowable($exception$request, self::MAIN_REQUEST);
        } finally {
            if ($pop) {
                $this->requestStack->pop();
            }
        }

        $response->sendHeaders();
        $response->sendContent();

        $this->terminate($request$response);
    }

    /** * Handles a request to convert it to a response. * * Exceptions are not caught. * * @throws \LogicException If one of the listener does not behave as expected * @throws NotFoundHttpException When controller cannot be found */
$this->headers->removeCookie($name$path);
    }

    /** * {@inheritdoc} * * @deprecated since 5.6, will be removed with 5.8. Use sendHeaders instead */
    public function sendCookies()
    {
        trigger_error(__CLASS__ . ':' . __METHOD__ . ' is deprecated. Please use sendHeaders instead', E_USER_DEPRECATED);
        $this->sendHeaders();
    }

    /** * {@inheritdoc} */
    public function unsetExceptions()
    {
        $this->_exceptions = [];
    }

    /** * {@inheritdoc} */
public function testClone()
    {
        $response = new Response();
        $responseClone = clone $response;
        $this->assertEquals($response$responseClone);
    }

    public function testSendHeaders()
    {
        $response = new Response();
        $headers = $response->sendHeaders();
        $this->assertSame($response$headers);
    }

    public function testSendInformationalResponse()
    {
        $response = new Response();
        $response->sendHeaders(103);

        // Informational responses must not override the main status code         $this->assertSame(200, $response->getStatusCode());

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