Robert Brewer committed a6d0849

Fix for #547 (serve_file still uses contentType instead of content_type). Thanks, michele!

Comments (0)

Files changed (2)

 from cherrypy.lib import cptools, http
-def serve_file(path, contentType=None, disposition=None, name=None):
+def serve_file(path, content_type=None, disposition=None, name=None):
     """Set status, headers, and body in order to serve the given file.
-    The Content-Type header will be set to the contentType arg, if provided.
+    The Content-Type header will be set to the content_ype arg, if provided.
     If not provided, the Content-Type will be guessed by its extension.
     If disposition is not None, the Content-Disposition header will be set
     response.headers['Last-Modified'] = http.HTTPDate(stat.st_mtime)
-    if contentType is None:
+    if content_type is None:
         # Set content-type based on filename extension
         ext = ""
         i = path.rfind('.')
         if i != -1:
             ext = path[i:].lower()
-        contentType = mimetypes.types_map.get(ext, "text/plain")
-    response.headers['Content-Type'] = contentType
+        content_type = mimetypes.types_map.get(ext, "text/plain")
+    response.headers['Content-Type'] = content_type
     if disposition is not None:
         if name is None:
                 def fileRanges():
                     for start, stop in r:
                         yield "--" + boundary
-                        yield "\nContent-type: %s" % contentType
+                        yield "\nContent-type: %s" % content_type
                         yield ("\nContent-range: bytes %s-%s/%s\n\n"
                                % (start, stop - 1, c_len))
         if content_types:
             r, ext = os.path.splitext(filename)
             content_type = content_types.get(ext[1:], None)
-        serve_file(filename, contentType=content_type)
+        serve_file(filename, content_type=content_type)
         return True
     except cherrypy.NotFound:
         # If we didn't find the static file, continue handling the


 Use cherrypy.lib.static.serve_file for that; it takes four
-serve_file(path, contentType=None, disposition=None, name=None)
+serve_file(path, content_type=None, disposition=None, name=None)
 Set "name" to the filename that you expect clients to use when they save
 your file. Note that the "name" argument is ignored if you don't also
 provide a "disposition" (usually "attachement"). You can manually set
-"contentType", but be aware that if you also use the encoding tool, it
+"content_type", but be aware that if you also use the encoding tool, it
 may choke if the file extension is not recognized as belonging to a known
-Content-Type. Setting the contentType to "application/x-download" works
+Content-Type. Setting the content_type to "application/x-download" works
 in most cases, and should prompt the user with an Open/Save dialog in
 popular browsers.