#6039: cached views don't retain document mime type (xml, json, etc.)
--------------------------+-------------------------------------------------
Reporter: skylar | Type: Bug
Status: new | Priority: Medium
Milestone: 1.2.x.x | Component: Cache
Version: 1.2 Final | Severity: Normal
Keywords: | Php_version: PHP 5
Cake_version: |
--------------------------+-------------------------------------------------
I tried caching some of those feeds today using controller-level view
caching and ran into a bug - cached views don't retain the mime type of
the document. That is, in most cases, a cached view (not elements) will be
served up as text/html by
CakePHP, not the type of the original document.
To recreate this, simply try offering a XML or JSON based view in a
controller, cache it, then load it twice. You should also use this in
conjunction with parseExtensions() which triggers the magic code which
sets the Content-type headers in this case. (If you're setting the header
via PHP in your view files, then the problem is a bit different). The
first request works correctly (uncached request), but the second request
will come back as text/html (except for an edge
case around XML).
The problem seems to be at line 508 of cake/libs/view/view.php.
(1.2.0.7962, but also present in 1.2.1.8004) This is where the view class
outputs a cached view file, if valid. The only check here for alternative
document mime-types is this confusing check for a layout named 'xml':
if ($this->layout === 'xml') {
header('Content-type: text/xml');
}
The cache file doesn't have any properties that retain the extension or
type that would have been used by RequestHandler (or other code) to find
the right content type. However, $this->here does capture the extension
implicitly.
It seems the proper thing for the caching mechanism to do is to store the
content type as a variable in the view cache file (eg, $this->ext or
$this->content_type) so that the proper header can be recreated with the
cache request. (This may be only in instances where the framework sets
the mime-header based on an extension). I don't know much about the
CakePHP internals so I'll defer primarily to explaining the situation in
hopes of filing a good bug and rallying a fix. This seems like a major
oversight in the caching system as feeds (ajax, json, xml) are becoming an
increasingly critical part of any modern web application.
--
Ticket URL: <https://trac.cakephp.org/ticket/6039>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---