Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set a custom Content Type for specific files without an extension #50

Closed
iserko opened this issue Nov 16, 2015 · 2 comments

Comments

@iserko
Copy link

iserko commented Nov 16, 2015

Apple's apple-app-site-association file must be served with the application/pkc7-mime content type (see: https://developer.apple.com/library/ios/documentation/Security/Reference/SharedWebCredentialsRef/), but Whitenoise is serving it with application/octet-stream, because the file has no extension and as such mimetypes determines it should provide the default octet-stream.

Would it be feasible to have some sort of file -> content type mapping which we could use whenever you would like to override the mimetypes library.

@evansd
Copy link
Owner

evansd commented Nov 16, 2015

I think the easiest way to handle this is to subclass WhiteNoise and use the add_extra_headers method which is explicitly provided to cope with these kinds of edge cases. The code would look something like this (untested):

class CusomWhiteNoise(DjangoWhiteNoise):

    def add_extra_headers(self, headers, path, url):
        if url == '/apple-app-site-association':
            headers['Content-Type'] = 'application/pkcs7-mime'

Would that be an acceptable solution?

@iserko
Copy link
Author

iserko commented Nov 16, 2015

@evansd that solution works just fine thanks

@iserko iserko closed this as completed Nov 16, 2015
evansd added a commit that referenced this issue Mar 4, 2016
This also allows us to ship with the correct mimetype for Apple's Shared
Web Credentials files:
https://developer.apple.com/library/ios/documentation/Security/Reference/SharedWebCredentialsRef/

This means the issue raised in #50 is now solved out-of-the-box without
any need for custom code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants