you can always open the file as binary; -)
Perhaps you can look at SimpleHTTPServer.py in this part of the code:
ctype = self.guess_type (path)
try:
# 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
Then, if you look at def guess_type (self, path): its very simple, it uses the file "extension"; -)
Return value is a string of the form type / subtype,
usable for a MIME Content-type header.
The default implementation looks the file extension
up in the table self.extensions_map, using application / octet-stream
as a default; however it would be permissible (if
slow) to look inside the data to make a better guess.
Just in case, the code:
base, ext = posixpath.splitext (path)
if ext in self.extensions_map:
return self.extensions_map [ext]
ext = ext.lower ()
if ext in self.extensions_map:
return self.extensions_map [ext]
else:
return self.extensions_map ['']
source share