Commits

Sylvain Hellegouarch committed 206dfce

added a content_types option to the static_filter. you can now do:
[/path]
static_filter.on = True
static_filter.content_types = {'atom': 'application/atom+xml', 'rss': 'application/rss+xml'}
static_filter.dir = '/path/to/'

http://host/feed.atom will return application/atom+xml
http://host/feed.rss will return application/rss+xml

  • Participants
  • Parent commits 2d2a81f

Comments (0)

Files changed (1)

cherrypy/filters/staticfilter.py

                 raise cherrypy.HTTPError(403) # Forbidden
             
         try:
-            cptools.serveFile(filename)
+            # you can set the content types for a complete directory per extension
+            content_types = config.get('static_filter.content_types', None)
+            content_type = None
+            if content_types:
+                root, ext = os.path.splitext(filename)
+                content_type = content_types.get(ext[1:], None)
+            cptools.serveFile(filename, contentType=content_type)
             request.execute_main = False
         except cherrypy.NotFound:
             # If we didn't find the static file, continue handling the
                         request.execute_main = False
                     except cherrypy.NotFound:
                         pass
-