diff Lib/SimpleHTTPServer.py @ 34383:18cff3ed74d3 2.4

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.
author Johannes Gijsbers <jlg@dds.nl>
date Mon, 10 Jan 2005 09:27:17 +0000
parents d9765eb59edd
children dee253a3116c
line wrap: on
line diff
--- a/Lib/SimpleHTTPServer.py	Sun Jan 09 15:32:37 2005 +0000
+++ b/Lib/SimpleHTTPServer.py	Mon Jan 10 09:27:17 2005 +0000
@@ -70,12 +70,11 @@
             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