diff options
author | Johannes Gijsbers <jlg@dds.nl> | 2005-01-10 09:27:17 (GMT) |
---|---|---|
committer | Johannes Gijsbers <jlg@dds.nl> | 2005-01-10 09:27:17 (GMT) |
commit | 9632e94afbe172ef30f394c8fb7d896ed6e43f87 (patch) | |
tree | 2efe4e5596e0bd0e8cbaea306aba5ea8929bd1ee | |
parent | a949c994531f9599f2251840aee511693eb51864 (diff) | |
download | cpython-9632e94afbe172ef30f394c8fb7d896ed6e43f87.zip cpython-9632e94afbe172ef30f394c8fb7d896ed6e43f87.tar.gz cpython-9632e94afbe172ef30f394c8fb7d896ed6e43f87.tar.bz2 |
Backport for bug #839496: always read files 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.
-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 93662ab..4d8eb77 100644 --- a/Lib/SimpleHTTPServer.py +++ b/Lib/SimpleHTTPServer.py @@ -70,12 +70,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 |