Skip to content

Commit

Permalink
Use application/javascript instead of application/x-javascript for th…
Browse files Browse the repository at this point in the history
…e Content-Type http header of JavaScript resources. Also see: http://stackoverflow.com/questions/9664282
  • Loading branch information
thet committed Jul 29, 2014
1 parent 03c5dad commit 1a67d2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Changelog
3.0.1 (unreleased)
------------------

- bugfix: do not convert URIs such as
- Use ``application/javascript`` instead of ``application/x-javascript`` for
the ``Content-Type`` http header of JavaScript resources. Also see:
http://stackoverflow.com/questions/9664282
[thet]

- bugfix: do not convert URIs such as
url(data:image/svg+xml;base64,PD94bWwgdmVyc2lv) to absolute urls
see https://github.com/plone/Products.ResourceRegistries/pull/16
[cillianderoiste]
Expand Down
44 changes: 22 additions & 22 deletions Products/ResourceRegistries/tests/testJSRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def afterSetUp(self):
def testPublishJSThroughTool(self):
response = self.publish(self.toolpath + '/test_rr_1.js')
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getHeader('Content-Type'), 'application/x-javascript;charset=utf-8')
self.assertEqual(response.getHeader('Content-Type'), 'application/javascript; charset=utf-8')

def testPublishNonMagicJSThroughTool(self):
self.setRoles(['Manager'])
Expand All @@ -462,7 +462,7 @@ def testPublishNonMagicJSThroughTool(self):
self.tool.registerScript('testmethod')
response = self.publish(self.toolpath + '/testmethod')
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getHeader('Content-Type'), 'application/x-javascript;charset=utf-8')
self.assertEqual(response.getHeader('Content-Type'), 'application/javascript; charset=utf-8')

def testPublishPageWithInlineJS(self):
# This one fails from string/utf-8 concatenation
Expand Down Expand Up @@ -576,14 +576,14 @@ def afterSetUp(self):
self.setRoles(['Manager'])
self.portal.invokeFactory('File',
id='testroot.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('red')")
self.portal.invokeFactory('Folder', 'subfolder')
self.portal.subfolder.invokeFactory('File',
id='testsubfolder.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('blue')")

self.tool.registerScript('testroot.js')
Expand Down Expand Up @@ -627,13 +627,13 @@ def testContextDependantInlineJS(self):
self.portal.invokeFactory('Folder', 'folder2')
self.portal.folder1.invokeFactory('File',
id='context.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('pink')")
self.portal.folder2.invokeFactory('File',
id='context.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('purple')")
self.tool.registerScript('context.js', inline=True)
self.setRoles(['Member'])
Expand Down Expand Up @@ -661,8 +661,8 @@ def afterSetUp(self):
self.setRoles(['Manager'])
self.portal.invokeFactory('File',
id='testroot.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('red')")

script = self.portal.restrictedTraverse('testroot.js')
Expand Down Expand Up @@ -758,13 +758,13 @@ def afterSetUp(self):
self.setRoles(['Manager'])
self.portal.invokeFactory('File',
id='testroot.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('green')")
self.portal.invokeFactory('File',
id='simple2.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('blue')")
self.setRoles(['Member'])
self.tool.setDebugMode(False)
Expand Down Expand Up @@ -846,13 +846,13 @@ def testLargerCompositionWithMiddleUncooked(self):
self.setRoles(['Manager'])
self.portal.invokeFactory('File',
id='testpurple.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('purple')")
self.portal.invokeFactory('File',
id='testpink.js',
format='application/x-javascript',
content_type='application/x-javascript',
format='application/javascript',
content_type='application/javascript',
file="window.alert('pink')")
self.setRoles(['Member'])
self.tool.registerScript('testpurple.js')
Expand Down Expand Up @@ -895,8 +895,8 @@ def afterSetUp(self):
self.portal.addDTMLMethod('testmethod.js', file=body)
self.portal.invokeFactory('File',
id='testfile.js',
format='application/x-javascript',
content_type='application/x-javascript;charset=utf-8',
format='application/javascript',
content_type='application/javascript; charset=utf-8',
file=body)
self.setRoles(['Member'])
self.tool.setDebugMode(False)
Expand Down
2 changes: 1 addition & 1 deletion Products/ResourceRegistries/tools/JSRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def getExternalCompressionOptions(self):
security.declareProtected(permissions.View, 'getContentType')
def getContentType(self):
"""Return the registry content type."""
return 'application/x-javascript;charset=utf-8'
return 'application/javascript; charset=utf-8'

security.declarePrivate('getResourceContent')
def getResourceContent(self, item, context, original=False, theme=None):
Expand Down

0 comments on commit 1a67d2a

Please sign in to comment.