Giter Site home page Giter Site logo

Comments (9)

joshkehn avatar joshkehn commented on August 17, 2024

New information on the header issue. I dug into the static package and added some debugging lines. The bad headers are generated when unicode strings are added for the Content-Type header as shown below:

10:02:04 web.1  | Exception: [('Date', 'Mon, 03 Mar 2014 15:02:04 -0000'), ('Last-Modified', 'Mon, 03 Mar 2014 14:40:23 -0000'), ('ETag', '1393857623.0'), ('Content-Type', u'text/javascript')]
10:02:04 web.1  | [03/Mar/2014 10:02:04] "GET /static/js/application.min.d96c71a1463c.js HTTP/1.1" 500 59

I cannot trace back where this is coming from. Any other suggestions @kennethreitz?

from dj-static.

lukearno avatar lukearno commented on August 17, 2024

Just hearing about this now: lukearno/static#4

Static just uses mimetypes to guess the type, which does not appear to give unicode:

>>> import mimetypes
>>> mimetypes.guess_type('/foo.js')
('application/javascript', None)

I tried it in Python 2.7 and 3.3.

from dj-static.

joshkehn avatar joshkehn commented on August 17, 2024

I tried that as well and noticed it behaved correctly. There are two sections for guessing the content type:

# Cling
def _guess_type(self, full_path):
    """Guess the mime type using the mimetypes module."""
    return mimetypes.guess_type(full_path)[0] or 'text/plain'

# Shock
def _guess_type(self, full_path):
    """Guess the mime type magically or using the mimetypes module."""
    magic = self._match_magic(full_path)
    if magic is not None:
        return (mimetypes.guess_type(magic.old_path(full_path))[0]
                or 'text/plain')
    else:
        return mimetypes.guess_type(full_path)[0] or 'text/plain'

I'm using Cling (assuming) with a stock implementation:

from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())

from dj-static.

lukearno avatar lukearno commented on August 17, 2024

Does django-pipeline add mappings to mimetypes?

from dj-static.

joshkehn avatar joshkehn commented on August 17, 2024

Digging into that I see:

'PIPELINE_MIMETYPES': (
    (b'text/coffeescript', '.coffee'),
    (b'text/less', '.less'),
    (b'application/javascript', '.js'),
    (b'text/x-sass', '.sass'),
    (b'text/x-scss', '.scss')
),

And then again in utils:

def guess_type(path, default=None):
    for type, ext in settings.PIPELINE_MIMETYPES:
        mimetypes.add_type(type, ext)
    mimetype, _ = mimetypes.guess_type(path)
    if not mimetype:
        return default
    return smart_str(mimetype)

I'm not sure how smart_str works or the implication of having binary strings declared in PIPELINE_MIMETYPES.

from dj-static.

lukearno avatar lukearno commented on August 17, 2024

I think that's it. Looks like it's fixed in the latest pipeline release (1.3.21).

jazzband/django-pipeline#297
jazzband/django-pipeline@f0b8f72

from dj-static.

joshkehn avatar joshkehn commented on August 17, 2024

I updated to 1.3.22 and this all appears to be working now. Yay for cross-package contamination of mimetypes..

from dj-static.

joshkehn avatar joshkehn commented on August 17, 2024

I just discovered an old version of pipeline in a project template and this being the first search result for the error saved me a lot of time. 👍

from dj-static.

gone avatar gone commented on August 17, 2024

Ditto - 👍

from dj-static.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.