本文整理汇总了PHP中TYPO3\Flow\Http\Request::hasHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::hasHeader方法的具体用法?PHP Request::hasHeader怎么用?PHP Request::hasHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\Flow\Http\Request
的用法示例。
在下文中一共展示了Request::hasHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTrustedProxyHeaderValues
/**
* Get the values of trusted proxy header.
*
* @param string $type One of the HEADER_* constants
* @param Request $request The request to get the trusted proxy header from
* @return \Iterator An array of the values for this header type or NULL if this header type should not be trusted
*/
protected function getTrustedProxyHeaderValues($type, Request $request)
{
$trustedHeaders = isset($this->settings['headers'][$type]) ? $this->settings['headers'][$type] : '';
if ($trustedHeaders === '' || !$request->getAttribute(Request::ATTRIBUTE_TRUSTED_PROXY)) {
(yield null);
return;
}
$trustedHeaders = array_map('trim', explode(',', $trustedHeaders));
foreach ($trustedHeaders as $trustedHeader) {
if ($request->hasHeader($trustedHeader)) {
(yield array_map('trim', explode(',', $request->getHeader($trustedHeader))));
}
}
(yield null);
}
示例2: makeStandardsCompliant
/**
* Analyzes this response, considering the given request and makes additions
* or removes certain headers in order to make the response compliant to
* RFC 2616 and related standards.
*
* It is recommended to call this method before the response is sent and Flow
* does so by default in its built-in HTTP request handler.
*
* @param \TYPO3\Flow\Http\Request $request The corresponding request
* @return void
* @api
*/
public function makeStandardsCompliant(Request $request)
{
if ($request->hasHeader('If-Modified-Since') && $this->headers->has('Last-Modified') && $this->statusCode === 200) {
$ifModifiedSinceDate = $request->getHeader('If-Modified-Since');
$lastModifiedDate = $this->headers->get('Last-Modified');
if ($lastModifiedDate <= $ifModifiedSinceDate) {
$this->setStatus(304);
$this->content = '';
}
} elseif ($request->hasHeader('If-Unmodified-Since') && $this->headers->has('Last-Modified') && ($this->statusCode >= 200 && $this->statusCode <= 299 || $this->statusCode === 412)) {
$unmodifiedSinceDate = $request->getHeader('If-Unmodified-Since');
$lastModifiedDate = $this->headers->get('Last-Modified');
if ($lastModifiedDate > $unmodifiedSinceDate) {
$this->setStatus(412);
}
}
if (in_array($this->statusCode, array(100, 101, 204, 304))) {
$this->content = '';
}
if ($this->headers->getCacheControlDirective('no-cache') !== NULL || $this->headers->has('Expires')) {
$this->headers->removeCacheControlDirective('max-age');
}
if ($request->getMethod() === 'HEAD') {
if (!$this->headers->has('Content-Length')) {
$this->headers->set('Content-Length', strlen($this->content));
}
$this->content = '';
}
if (!$this->headers->has('Content-Length')) {
$this->headers->set('Content-Length', strlen($this->content));
}
if ($this->headers->has('Transfer-Encoding')) {
$this->headers->remove('Content-Length');
}
}