diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-06 21:34:39 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-06 21:34:39 (GMT) |
commit | 0f7cddc308b297e6a1c2dd61503acea38401656f (patch) | |
tree | c23dda9b8ae93549e83bb939dbd9ae09f49701de /Lib/SimpleHTTPServer.py | |
parent | aaca97810308dbfd9147cce98384f50d4ae4a3d3 (diff) | |
download | cpython-0f7cddc308b297e6a1c2dd61503acea38401656f.zip cpython-0f7cddc308b297e6a1c2dd61503acea38401656f.tar.gz cpython-0f7cddc308b297e6a1c2dd61503acea38401656f.tar.bz2 |
Issue839496: SimpleHTTPServer should open all files in binary mode.
Forward-port of 38255 (2005/01/15!)
This was already fixed in 2.4, but never merged into trunk...
py3k is already right, thanks to the bytes/str distinction!
Should be backported to 2.5.
Diffstat (limited to 'Lib/SimpleHTTPServer.py')
-rw-r--r-- | Lib/SimpleHTTPServer.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/SimpleHTTPServer.py b/Lib/SimpleHTTPServer.py index e79a478..0110da0 100644 --- a/Lib/SimpleHTTPServer.py +++ b/Lib/SimpleHTTPServer.py @@ -79,12 +79,11 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): 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 |