我用Symfony2为iOS应用程序创建了一个API。该应用程序通过标题参数
if-modified-since
发送GET请求。
在控制器中,我检查参数并在日期更新时返回数据。但是,在生产环境中,Symfony2中的参数将在类"If-Modified-Since" = "Thu, 07 Nov 2013 11:50:52 GMT";
Symfony\Component\HttpKernel\HttpCache\HttpCache.php
中被删除。下面是该类中的函数。/**
* Forwards the Request to the backend and determines whether the response should be stored.
*
* This methods is triggered when the cache missed or a reload is required.
*
* @param Request $request A Request instance
* @param Boolean $catch whether to process exceptions
*
* @return Response A Response instance
*/
protected function fetch(Request $request, $catch = false)
{
$subRequest = clone $request;
// send no head requests because we want content
$subRequest->setMethod('GET');
// avoid that the backend sends no content
$subRequest->headers->remove('if_modified_since');
$subRequest->headers->remove('if_none_match');
$response = $this->forward($subRequest, $catch);
if ($this->isPrivateRequest($request) && !$response->headers->hasCacheControlDirective('public')) {
$response->setPrivate(true);
} elseif ($this->options['default_ttl'] > 0 && null === $response->getTtl() && !$response->headers->getCacheControlDirective('must-revalidate')) {
$response->setTtl($this->options['default_ttl']);
}
if ($response->isCacheable()) {
$this->store($request, $response);
}
return $response;
}
看起来Symfony找不到此请求的响应的缓存条目,并删除此参数以确保有内容可以缓存,但它从未找到条目。即使经过多次重新加载,仍然是这样。
我需要在控制器中使用此参数,目前应用程序没有机会更改参数或发送具有日期值的其他参数。
我是否需要进行一些配置或其他操作?
如果有人能帮助我,我将非常感激。
web/app.php
中包装内核了? - Jasper N. Brouwer