Commits

David Beitey committed 65e529e

Ensure bundled resources are delivered with correct Content-Type header

Comments (0)

Files changed (4)

 0.15 (unreleased)
 =================
 
-- Nothing changed yet.
+- Ensure published bundles carry the correct Content-Type header. Previously,
+  all bundles were delivered with `text/html`.
 
 
 0.14 (2012-10-30)

fanstatic/publisher.py

         return webob.Response(
             body=b'\n'.join(contents),
             last_modified=mtime,
+            **self.kw
         ).conditional_response_app
 
 

tests/test_bundle.py

     needed = NeededResources(resources=[x1, x2, x4, x5], bundle=True)
     assert needed.render() == '''<link rel="stylesheet" type="text/css" href="/fanstatic/foo/:bundle:a.css;b.css" />
 <link rel="stylesheet" type="text/css" href="/fanstatic/foo/subdir/subdir/:bundle:x4.css;x5.css" />'''
+

tests/test_publisher.py

     request = webob.Request.blank('/fanstatic/foo/test.js')
     response = request.get_response(delegator)
     assert response.body == b'/* a test */'
+    assert response.content_type == 'text/javascript'
 
     # A deeper fanstatic.
     request = webob.Request.blank('/foo/bar/fanstatic/foo/test.js')
     response = request.get_response(delegator)
     assert response.body == b'/* a test */'
+    assert response.content_type == 'text/javascript'
 
     request = webob.Request.blank('/somethingelse')
     response = request.get_response(delegator)
     assert response.body == 'Hello world!'
+    #Default content type from WebOb
+    assert response.content_type == 'text/html'
 
 
 def test_publisher_ignores(tmpdir):
     assert response.body == b'''/* a test 1 */
 /* a test 2 */'''
     assert response.cache_control.max_age is None
+    assert response.content_type == 'text/javascript'
 
     request = webob.Request.blank('/foo/:version:123/:bundle:test1.js;test2.js')
     response = request.get_response(app)
     assert response
     assert response.cache_control.max_age is not None
+    assert response.content_type == 'text/javascript'
 
     # Dirty bundles yield a 404:
     request = webob.Request.blank('/foo/:bundle:test1.js;test2.js;test1.js')
     assert response.body == b'''r1
 r2
 r4'''
+    assert response.content_type == 'text/css'
 
     # An incorrect bundle, as the order of the paths does not correspond to
     # the dependency order of the Resources.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.