mercurial/hgweb/common.py
changeset 2514 419c42223bee
parent 2391 d351a3be3371
child 2858 345bac2bc4ec
equal deleted inserted replaced
2513:f22e3e8fd457 2514:419c42223bee
    15     if os.path.exists(os.path.join(cl_path)):
    15     if os.path.exists(os.path.join(cl_path)):
    16         return os.stat(cl_path).st_mtime
    16         return os.stat(cl_path).st_mtime
    17     else:
    17     else:
    18         return os.stat(hg_path).st_mtime
    18         return os.stat(hg_path).st_mtime
    19 
    19 
    20 def staticfile(directory, fname):
    20 def staticfile(directory, fname, req):
    21     """return a file inside directory with guessed content-type header
    21     """return a file inside directory with guessed content-type header
    22 
    22 
    23     fname always uses '/' as directory separator and isn't allowed to
    23     fname always uses '/' as directory separator and isn't allowed to
    24     contain unusual path components.
    24     contain unusual path components.
    25     Content-type is guessed using the mimetypes module.
    25     Content-type is guessed using the mimetypes module.
    34             return ""
    34             return ""
    35         path = os.path.join(path, part)
    35         path = os.path.join(path, part)
    36     try:
    36     try:
    37         os.stat(path)
    37         os.stat(path)
    38         ct = mimetypes.guess_type(path)[0] or "text/plain"
    38         ct = mimetypes.guess_type(path)[0] or "text/plain"
    39         return "Content-type: %s\n\n%s" % (ct, file(path).read())
    39         req.header([('Content-type', ct),
       
    40                     ('Content-length', os.path.getsize(path))])
       
    41         return file(path).read()
    40     except (TypeError, OSError):
    42     except (TypeError, OSError):
    41         # illegal fname or unreadable file
    43         # illegal fname or unreadable file
    42         return ""
    44         return ""