AssetManager icon indicating copy to clipboard operation
AssetManager copied to clipboard

Set MIME type based on requested asset

Open renaatdemuynck opened this issue 9 years ago • 12 comments
trafficstars

This fixes issue #200. MIME types are now determined based on the requested asset. Also fixed some tests that were failing on my Windows machine due to the use of slashes instead of DIRECTORY_SEPARATORs.

renaatdemuynck avatar Nov 17 '16 21:11 renaatdemuynck

Can this pull request be accepted?

renaatdemuynck avatar Mar 15 '17 07:03 renaatdemuynck

I had a comment here, but I never clicked on comment... It must have been a slow day.

I don't know if I can, it looks very much like it will break for existing implementations (as you had to alter the tests).

RWOverdijk avatar Mar 15 '17 08:03 RWOverdijk

@renaatdemuynck - If I'm reading this right this changes the responsibility of figuring out the Mime type from the actual file, to the file being requested?

So if I map test.css to real file test.js (not sure why I'd do that but I could) the mime type coming back would be text/css instead of the actual application/javascript for the file?

Personally I'm never a fan of trusting the client but is there some benefit here to letting the client tell you what the server should be serving as the mimetype, verses the actual files themselves?

wshafer avatar Jul 24 '17 14:07 wshafer

Just saw the open issue here: https://github.com/RWOverdijk/AssetManager/issues/200 which answers my question

wshafer avatar Jul 24 '17 14:07 wshafer

Merging this would be a bump to 2.0.0. I'm wondering if maybe this behavior should be made configurable instead. Thoughts?

RWOverdijk avatar Jul 25 '17 07:07 RWOverdijk

@RWOverdijk - I was going go ahead and put this into the v2 branch.

wshafer avatar Jul 26 '17 17:07 wshafer

@wshafer I'd prefer that, too.

RWOverdijk avatar Jul 28 '17 07:07 RWOverdijk

Sorry, I missed the whole conversation. I just got back from vacation. Thanks for merging this into v2. @RWOverdijk: About the ability to configure, I believe the standard behavior should be the new one. You could make an option to revert to the old behavior for BC reasons, but I don't see a real need for it.

renaatdemuynck avatar Aug 16 '17 07:08 renaatdemuynck

This is going to be a major version bump. So I'll just make it the default behavior. It makes more sense because there's another change coming to mimetypes and this fits perfectly with that change as well.

Thanks for the help

wshafer avatar Aug 24 '17 23:08 wshafer

This breaks my code, we can not mix css, less, sass files now :( but we should do it.

// some_config.php
[
    'resolver_configs' => [
        'collections' => [
            'assets/css/base.css' => [
                'assets/less.css',
                'assets/sass.css',
                'assets/other_file.css'
            ],
            'assets/less.css' => [
                'path/less.less',
            ],
            'assets/sass.css' => [
                'path/sass.less',
            ],

    ],
    'filters' => [
        'assets/less.css' => [
            [
                'service' => 'SomeLessCompiler',
            ]
        ],
        'assets/sass.css' => [
            [
                'service' => 'SomeSassCompiler',
            ]
        ]
    ],
]

This code will fail with error "... doesn't have the expected mime-type ...", but logically everything should be fine

[
    'resolver_configs' => [
        'collections' => [
            'assets/base.css' => [
                'assets/less.less',
            ],

    ],
    'filters' => [
        'assets/base.css' => [
            [
                'service' => 'SomeLessCompiler',
            ]
        ],
    ],
]

assets/base.css will output with mime type text/less, but actual type is text/css after compilation

thestanislav avatar Nov 22 '17 21:11 thestanislav

Thanks for the report.

I believe I addressed this issue with a different merge for v2, but I’ll test this on my end and make sure this use case is working before I tag it.

wshafer avatar Nov 22 '17 21:11 wshafer

@thestanislav - I have finally tagged v 2.0.0. I have also confirmed that the following config will work just fine.

<?php

return [
    'asset_manager' => [
        'resolver_configs' => [
            'collections' => [
                'assets/css/base.css' => [
                    'assets/less.css',
                    'assets/scss.css',
                ],
            ],
            'private_collections' => [
                'assets/less.css' => [
                    __DIR__.'/../../assets/less.less',
                ],
                'assets/scss.css' => [
                    __DIR__.'/../../assets/scss.scss',
                ],
            ],
        ],

        'filters' => [
            'assets/less.css' => [
                [
                    'filter' => 'Lessphp'
                ]
            ],

            'assets/scss.css' => [
                [
                    'filter' => 'Scssphp'
                ]
            ],
        ]
    ]
];

To update to the beta version see the upgrade guide here

Let me know if you encounter any other issues.

wshafer avatar Dec 27 '17 22:12 wshafer