text mode may cause newline translations, making the actual size of the content
transmitted *less* than the content-length.
else:
return self.list_directory(path)
ctype = self.guess_type(path)
- if ctype.startswith('text/'):
- mode = 'r'
- else:
- mode = 'rb'
try:
- f = open(path, mode)
+ # Always read in binary mode. Opening files in text mode may cause
+ # newline translations, making the actual size of the content
+ # transmitted *less* than the content-length!
+ f = open(path, 'rb')
except IOError:
self.send_error(404, "File not found")
return None