20 parent::__construct();
29 public function flush($text =
'')
32 while (@ob_end_clean())
37 if (function_exists(
'fastcgi_finish_request'))
40 $this->writeHeaders();
43 fastcgi_finish_request();
52 $size = ob_get_length();
54 $this->
addHeader(
'Content-Length', $size);
56 $this->writeHeaders();
107 $key = $cookie->getName() .
'.' . $cookie->getDomain() .
'.' . $cookie->getPath();
108 if ($replace || !isset($this->cookies[$key]))
110 if ($checkExpires && $cookie->getExpires() > 0)
113 static $askToStore =
null;
114 if ($askToStore ===
null)
116 $askToStore = Config\Option::get(
'main',
'ask_to_store_cookies');
118 if ($askToStore ===
'Y')
120 if (Context::getCurrent()->getRequest()->getCookiesMode() !==
'Y')
123 $cookie->setExpires(0);
128 $this->cookies[$key] = $cookie;
142 $cookie =
new Web\Cookie(self::STORE_COOKIE_NAME,
'Y');
147 $cookie =
new Web\Cookie(self::STORE_COOKIE_NAME,
'N', 0);
171 public function writeHeaders()
175 if ($this->lastModified !==
null)
177 $this->
flushHeader([
'Last-Modified', gmdate(
'D, d M Y H:i:s', $this->lastModified->getTimestamp()) .
' GMT']);
180 foreach ($this->
getHeaders() as $name => $values)
182 if (is_array($values))
184 foreach ($values as $value)
189 elseif ($values !==
'')
199 $cookiesCrypter =
new Web\CookiesCrypter();
200 foreach ($this->cookies as $cookie)
202 if (!$cookiesCrypter->shouldEncrypt($cookie))
209 foreach ($cookiesCrypter->encrypt($cookie) as $cryptoCookie)
219 if (($status = $this->headers->getStatus()) > 0)
221 $reasonPhrase = $this->headers->getReasonPhrase();
222 if ($reasonPhrase !=
'')
224 $status .=
' ' . $reasonPhrase;
227 $httpStatus = Config\Configuration::getValue(
'http_status');
228 $cgiMode = (stristr(php_sapi_name(),
'cgi') !==
false);
230 if ($cgiMode && !$httpStatus)
232 header(
'Status: ' . $status);
243 if (is_array($header))
245 header($header[0] .
': ' . $header[1]);
260 'expires' => $cookie->getExpires(),
261 'path' => $cookie->getPath(),
262 'domain' => $cookie->getDomain(),
263 'secure' => $cookie->getSecure(),
264 'httponly' => $cookie->getHttpOnly(),
267 if (($sameSite = $cookie->getSameSite()) !==
null)
269 $params[
'samesite'] = $sameSite;
290 if (preg_match(
'#^(\d+) *(.*)#', $status, $find))
292 $this->headers->setStatus((
int)$find[1], trim($find[2]));
309 $context = Context::getCurrent();
310 if ($context !==
null)
312 $server = $context->getServer();
313 if ($server !==
null)
315 return $server->get(
'SERVER_PROTOCOL');
329 if ($this->lastModified ===
null || $time->getTimestamp() > $this->lastModified->getTimestamp())
331 $this->lastModified = $time;
352 foreach ($this->
getHeaders() as $headerName => $values)
354 if ($this->shouldIgnoreHeaderToClone($headerName))
359 if ($httpHeaders->get($headerName))
364 $httpHeaders->add($headerName, $values);
373 if ($status !== HttpHeaders::DEFAULT_HTTP_STATUS)
381 private function shouldIgnoreHeaderToClone($headerName)
383 return in_array(strtolower($headerName), [
copyHeadersTo(HttpResponse $response)
allowPersistentCookies($mode)
setCookie(Web\Cookie $cookie)
addHeader($name, $value='')
setHeaders(Web\HttpHeaders $headers)
addCookie(Web\Cookie $cookie, $replace=true, $checkExpires=true)
setLastModified(Type\DateTime $time)