Webiny\Component\Http\Response::sendHeaders PHP Method

sendHeaders() public method

This also sends the cache control headers.
public sendHeaders ( )
    public function sendHeaders()
    {
        // first build headers -> only if they haven't already been sent
        if (!headers_sent()) {
            // status code header
            header(self::PROTOCOL . ' ' . $this->getStatusCode() . ' ' . $this->statusMessage);
            // other headers
            foreach ($this->headers as $k => $v) {
                header($k . ': ' . $v);
            }
            // cache control headers
            $cacheControlHeaders = $this->cacheControl->getCacheControl();
            foreach ($cacheControlHeaders as $k => $v) {
                header($k . ': ' . $v);
            }
        }
        return $this;
    }

Usage Example

Esempio n. 1
0
 /**
  * Redirect the request to the given url.
  *
  * @param string|UrlObject $url
  * @param string|int|array $headers Headers that you wish to send with your request.
  * @param int              $redirectCode
  */
 protected static function httpRedirect($url, $headers = [], $redirectCode = 301)
 {
     $url = new UrlObject($url);
     $headers['Location'] = $url->val();
     $response = new Response('', $redirectCode, $headers);
     $response->sendHeaders();
 }