HUE-5717 [backend] Some operating system incorrectly detect javascript mime-type as text/x-js instead of application/javascript

Review Request #9455 - Created Jan. 31, 2017 and submitted

Prakash Ranade
hue
master
HUE-5717
hue
enricoberti, jennykim, johan, krish, ranade, romain, subrata, weixia
commit 3fa4f9bc3ea0c3f1f8c1b141733d2d8722400d85
Author: Prakash Ranade <ranade@cloudera.com>
Date:   Mon Jan 30 17:49:05 2017 -0800

    HUE-5717 [backend] Some operating system incorrectly detect javascript mime-type as text/x-js instead of application/javascript

:100644 100644 f24b63f... 58f901f... M	desktop/core/src/desktop/middleware.py
:100644 100644 eea9b36... 2f52cf3... M	desktop/core/src/desktop/settings.py

Tested on SLES 11SP4, CentOS 7.2. Tested manually modifying /etc/mime.types and checking django static file serve generates wrong mime-type for ".js" file. And then this changes in middleware fix the proper mime-type for ".js" file.

  • 0
  • 0
  • 3
  • 1
  • 4
Description From Last Updated
  1. 
      
  2. desktop/core/src/desktop/middleware.py (Diff revision 1)
     
     

    Need a comment about SLES 11 as example of OS with the issue

  3. desktop/core/src/desktop/middleware.py (Diff revision 1)
     
     

    Curious, why can't we do in init()

    mimetypes.guess_type('dummy.js')
    ('application/javascript', None)

    and unload if we get 'application/javascript'?

    1. In the init function if we hard-code js file path then we can perform mimetypes.guess_types("ABSOLUTE_PATH") and then load/unload middleware. But hard-coding which ABSOLUTE_PATH file?

    2. I think it looks only at the extension and the doc confirmed it, so even

      mimetypes.guess_type('dummy.js')

      should work?

      Main worry was that the doc says it is a Python 2.7, but Django uses the same lib, so we ship it somehow already and we should be good.

    3. oh i was not sure "dummy.js" (just name) is enough. Tested on SLES 11SP4 and CentOS 6.6, 7.2 and "dummy.js" works.

    4. Nice! So we could do that in the init() and unload if guessing returns the expected 'application/javascript'

  4. 
      
  1. 
      
  2. desktop/core/src/desktop/middleware.py (Diff revision 3)
     
     

    import on top of file with standard modules

  3. desktop/core/src/desktop/middleware.py (Diff revision 3)
     
     
     
     
     
     
     
     
     
     

    if mimetypes.guess_type("dummy.js")[0] in jsmimetypes:
    LOG.info('Unloading MimeTypeJSFileFixStreamingMiddleware')
    raise exceptions.MiddlewareNotUsed

    and [0] works as worse case it will be None according to the doc.

  4. 
      
  1. Nice!

  2. 
      
Review request changed

Status: Closed (submitted)

Loading...