Commits

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)
     cptools.validate_since()
     
-    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))
                         bodyfile.seek(start)
         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

tutorial/tut09_files.py

 Use cherrypy.lib.static.serve_file for that; it takes four
 arguments:
 
-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.
 
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.