headers example

// Per spec, MUST be sent with each request, if possible.         // http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html         if (isset($this->headers['Date']) && PHP_SAPI !== 'cli-server') {
            $this->setDate(DateTime::createFromFormat('U', (string) Time::now()->getTimestamp()));
        }

        // HTTP Status         header(sprintf('HTTP/%s %s %s', $this->getProtocolVersion()$this->getStatusCode()$this->getReasonPhrase()), true, $this->getStatusCode());

        // Send all of our headers         foreach (array_keys($this->headers()) as $name) {
            header($name . ': ' . $this->getHeaderLine($name), false, $this->getStatusCode());
        }

        return $this;
    }

    /** * Sends the Body of the message to the browser. * * @return $this */
    
switch ($matches[1]) {
                    case 'request':
                        $result = Psr7\Message::toString($request);
                        break;
                    case 'response':
                        $result = $response ? Psr7\Message::toString($response) : '';
                        break;
                    case 'req_headers':
                        $result = \trim($request->getMethod()
                                .' '.$request->getRequestTarget())
                            .' HTTP/'.$request->getProtocolVersion()."\r\n"
                            .$this->headers($request);
                        break;
                    case 'res_headers':
                        $result = $response ?
                            \sprintf(
                                'HTTP/%s %d %s',
                                $response->getProtocolVersion(),
                                $response->getStatusCode(),
                                $response->getReasonPhrase()
                            )."\r\n".$this->headers($response)
                            : 'NULL';
                        break;
                    
static::assertSame(['foo' => 'bar']$facade->request());
    }

    public function testHeaders(): void
    {
        $request = new Request();
        $request->headers->set('foo', 'bar');
        $request->headers->set('accept', 'application/json');

        $facade = new RequestFacade($request);

        static::assertSame(['accept' => ['application/json']]$facade->headers());
    }

    public function testCookies(): void
    {
        $request = new Request();
        $request->cookies->set('foo', 'bar');

        $facade = new RequestFacade($request);

        static::assertSame(['foo' => 'bar']$facade->cookies());
    }

    
<?php endforeach ?> <?php if ($empty) : ?> <div class="alert"> No $_GET, $_POST, or $_COOKIE Information to show. </div> <?php endif; ?> <?php $headers = $request->headers(); ?> <?php if (empty($headers)) : ?> <h3>Headers</h3> <table> <thead> <tr> <th>Header</th> <th>Value</th> </tr> </thead> <tbody>

        }

        foreach ($request->getGet() as $name => $value) {
            $data['vars']['get'][esc($name)] = is_array($value) ? '<pre>' . esc(print_r($value, true)) . '</pre>' : esc($value);
        }

        foreach ($request->getPost() as $name => $value) {
            $data['vars']['post'][esc($name)] = is_array($value) ? '<pre>' . esc(print_r($value, true)) . '</pre>' : esc($value);
        }

        foreach ($request->headers() as $header) {
            $data['vars']['headers'][esc($header->getName())] = esc($header->getValueLine());
        }

        foreach ($request->getCookie() as $name => $value) {
            $data['vars']['cookies'][esc($name)] = esc($value);
        }

        $data['vars']['request'] = ($request->isSecure() ? 'HTTPS' : 'HTTP') . '/' . $request->getProtocolVersion();

        $data['vars']['response'] = [
            'statusCode'  => $response->getStatusCode(),
            
/** * 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;
    }
}

    public function make($request, ResponseInterface $response): bool
    {
        if ($this->ttl === 0) {
            return true;
        }

        $headers = [];

        foreach ($response->headers() as $header) {
            $headers[$header->getName()] = $header->getValueLine();
        }

        return $this->cache->save(
            $this->generateCacheKey($request),
            serialize(['headers' => $headers, 'output' => $response->getBody()]),
            $this->ttl
        );
    }

    /** * Gets the cached response for the request. * * @param CLIRequest|IncomingRequest $request */

    public function cachePage(Cache $config)
    {
        $headers = [];

        foreach ($this->response->headers() as $header) {
            $headers[$header->getName()] = $header->getValueLine();
        }

        return cache()->save($this->generateCacheName($config)serialize(['headers' => $headers, 'output' => $this->output])static::$cacheTTL);
    }

    /** * Returns an array with our basic performance stats collected. */
    public function getPerformanceStats(): array
    {
        

    public function getHeaders(): array
    {
        return $this->headers();
    }

    /** * Returns a single header object. If multiple headers with the same * name exist, then will return an array of header objects. * * @return array|Header|null * * @deprecated Use Message::header() to make room for PSR-7 * * @TODO Incompatible return value with PSR-7 * * @codeCoverageIgnore */
Home | Imprint | This part of the site doesn't use cookies.