Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

RFC: Serving the cache.manifest file #136

Open
NotBobTheBuilder opened this issue Dec 11, 2012 · 3 comments
Open

RFC: Serving the cache.manifest file #136

NotBobTheBuilder opened this issue Dec 11, 2012 · 3 comments

Comments

@NotBobTheBuilder
Copy link
Member

To integrate nifty Application Cache stuff, CFM needs to serve a manifest with mime type of "text/cache-manifest". What is the most suitable way to do this?

So far, I've looked at index.php and how it serves mime types according to whether the request is for an image, data from the API or a browser looking for HTML, but there's no obvious way of fitting in the manifest.

It seems a bit "ugly" to hijack the control block from lines 35-90 (which test whether the request is for API or media) just to check if this is a request for the manifest.

Modifying .htaccess so that the manifest request doesn't get redirected through index.php is an option, but it isn't perfect and then requires the server to be configured to serve the "text/cache-manifest" mime type.

Is there a tidier way of doing this?

@JonTheNiceGuy
Copy link
Member

So, as I mentioned by mail, you'll first need to add to the table defined here:
https://github.com/CampFireManager/cfm2/blob/master/classes/Base/Request.php#L28

    'text/cache-manifest' => array(
        'media' => true, 'rest' => false, 'site' => false
    ),

It would probably be worth adding an application extension here:
https://github.com/CampFireManager/cfm2/blob/master/classes/Base/Request.php#L543

                    case 'manifest':
                        $this->setAcceptType(
                            'text/cache-manifest',
                            $arrDenyTypes
                        );
                        break;

Then, if you can use the /media directory, do so, otherwise, some code in here to handle the manifest file:
https://github.com/CampFireManager/cfm2/blob/master/index.php#L37

if ($arrPathItems[0] == 'cache' && $arrPathItems[1] == 'manifest') {
    $file = dirname(__FILE__) . '/path/to/cache.manifest';
    if (is_file($file)) {
        Base_Response::sendResumableFile($file, TRUE, $objRequest->get_strPrefAcceptType());
    } else {
        Base_Response::sendHttpResponse(404, null, $objRequest->get_strPrefAcceptType());
    }

Or, instead of the sendResumableFile, use Base_Response::sendHttpResponse(200, $cache_content, $objRequest->get_strPrefAcceptType()) instead.

Obviously, it's been a while since I've looked at some of this, so some of the functions might not quite work the way I remember they do, but I think this is right.

@NotBobTheBuilder
Copy link
Member Author

Cheers for that!

I've just realised - a lot of the files to be cached will need to have their absolute location held in the manifest, so storing them in /media won't work without some manual modification of the manifest.

Is it possible to have the manifest file run through Smarty before being served up?

@JonTheNiceGuy
Copy link
Member

Er, probably, but you'll have to tweak either Base_Response::render() (I think) or index.php.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants