Add the Date header if it's missing.

@see https://tools.ietf.org/html/rfc2616#section-14.18

@param int $statusCode
@param \Symfony\Component\HttpFoundation\ResponseHeaderBag $headerBag
499265
protected function addDateHeaderIfNecessary($statusCode, $headerBag)
    {
        if ($statusCode >= 200 && $statusCode < 500 && ! $headerBag->has('Date')) {
            $date = DateTime::createFromFormat('U', time(), new DateTimeZone('UTC'));

            $headerBag->set('Date', $date->format('D, d M Y H:i:s').' GMT');
        }
    }
8847
public function setStatusCode($code = null)
    {
        if (!empty($code)) {
            $this->_statusCode = $code;
            http_response_code($this->_statusCode); // this sends the http status code
        }
    }
630528
protected function _setStatus($code, $reasonPhrase = '')
    {
        if (!isset($this->_statusCodes[$code])) {
            throw new InvalidArgumentException(sprintf(
                'Invalid status code: %s. Use a valid HTTP status code in range 1xx - 5xx.',
                $code
            ));
        }

        $this->_status = $code;
        if (empty($reasonPhrase)) {
            $reasonPhrase = $this->_statusCodes[$code];
        }
        $this->_reasonPhrase = $reasonPhrase;
        $this->_setContentType();
    }
427102
public function makeJsonReponse($status_code, $body)
    {
        $this->getResponse()->setBody(json_encode($body, JSON_UNESCAPED_SLASHES));
        $this->getResponse()->setStatusCode($status_code);
        $this->getResponse()->addHeader("Content-type", "application/json");

        return $this->getResponse();
    }
292131
protected function validateResponse($statusCode) {
        switch($statusCode) {
            case 204:
                throw new Exceptions\RateLimitException('Too many requests');
            case 403:
                throw new Exceptions\InvalidApiKeyException(sprintf('Key %s is invalid', $this->_apiKey));
            default:
                return;
        }
    }
693361
public function setExpectedStatusCode($statusCodes)
    {
        if (!is_array($statusCodes)) {
            $this->_expectedStatusCodes[] = $statusCodes;
        } else {
            $this->_expectedStatusCodes = $statusCodes;
        }
    }
120524
public function setStatusCode($statusCode, $message = null)
    {
        $this->statusCode = (int) $statusCode;

        // Add status message to meta array
        $this->addMeta(['status' => ['code' => (int) $statusCode]]);

        // Set optional status message if present
        if (!empty($message)) {
            $this->setStatusMessage($message);
        }

        return $this;
    }
400557
protected function setResponseError($error, int $statusCode = 500) : void
    {
        if ($error instanceof \Exception) {
            $error = $error->getMessage();
        }

        $this->response['message'] = (string)$error;
        $this->response['status'] = $statusCode;
    }
261318
public function redirect($location, $statusCode = 302) {
        $this->response->setHeader('Location', $location, true, $statusCode);
        return $this;
    }
851337
public function setHeaderResponse($statusCode, $message = '')
    {
        $this->statusCode = $statusCode;
        $this->message = $message;
        if ($message == '') {
            $this->message = self::$defaultMessages[$statusCode];
        }

        if (empty($this->message)) {
            throw new RestException('Invalid http response status code: ' . $statusCode);
        }

        return $this;
    }
1299647
protected function getCodeResponse($statusCode)
    {
        $this->checkParameters();

        /** @var ResponsesInterface $responses */
        $responses = $this->getIntegration()->getFromContainer(ResponsesInterface::class);
        $outputMediaType = $this->codecMatcher->getEncoderRegisteredMatchedType();

        return $responses->getResponse($statusCode, $outputMediaType, null, $this->supportedExtensions);
    }
890161
private function reportMissingHeaders(HeaderBag $headers)
    {
        foreach ($this->reportMissingHeaders as $header)
        {
            if (
                ! $headers->has($header)
                and empty($this->reportMissingExceptions[strtolower($header)])
            ) {
                $this->addError(
                    "Missing security header: '$header'",
                    E_USER_WARNING
                );
            }
        }
    }
113216
protected function generateResponse($statusCode, $json)
    {
        if (empty($json) && $statusCode == Response::REST_SUCCESS_NO_CONTENT) {
            return new Response(array(), $statusCode);
        } else {
            $body = json_decode($json, true);
            if ($body == null) {
                throw new ClientException('Error while sending request to api; Received invalid json: ' . $json, ClientException::SERVER_UNAVAILABLE);
            }
            $response = new Response($body, $statusCode);
            $this->validateServerResponse($response);

            return $response;
        }
    }
1360765
public function setStatusCode($statusCode)
    {
        $statusCode = intval($statusCode);
        $this->statusCode = ($statusCode > 0) ? $statusCode : self::RESPONSE_OK;
        return $this;
    }
848689
public function setStatusCode(int $statusCode): self
    {
        if (!array_key_exists($statusCode, Response::$statusTexts)) {
            $this->internalServerError('Invalid status code in ' . __METHOD__, Response::$statusTexts);
        }

        $this->statusCode = $statusCode;

        return $this;
    }
769713
public function onBeforeHTTPError($statusCode, $request)
    {
        if (Director::is_ajax()) {
            return;
        }
        $response = ErrorPage::response_for($statusCode);
        if ($response) {
            throw new HTTPResponse_Exception($response, $statusCode);
        }
    }
1220303
public function modify(HeaderBag &$headers)
    {
        $cspHeaders = [
            'Content-Security-Policy' => 'csp',
            'Content-Security-Policy-Report-Only' => 'cspro',
        ];

        foreach ($cspHeaders as $header => $type)
        {
            if ($this->combine)
            {
                $otherPolicyHeaders = $headers->getByName($header);

                $policies = [$this->{$type.'Config'}];

                foreach ($otherPolicyHeaders as $otherPolicy)
                {
                    $policies[]
                        = self::deconstructCSP($otherPolicy->getValue());
                }

                $this->{$type.'Config'} = self::mergeCSPList($policies);
            }

            $value = $this->{'compile'.strtoupper($type)}();

            if (empty($value))
            {
                continue;
            }

            $headers->{($this->combine ? 'replace' : 'add')}($header, $value);

            if ($this->sendLegacyHeaders)
            {
                $headers->{($this->combine ? 'replace' : 'add')}("X-$header", $value);
            }
        }
    }