Kaydet (Commit) 9632e94a authored tarafından Johannes Gijsbers's avatar Johannes Gijsbers

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.
üst a949c994
...@@ -70,12 +70,11 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -70,12 +70,11 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
else: else:
return self.list_directory(path) return self.list_directory(path)
ctype = self.guess_type(path) ctype = self.guess_type(path)
if ctype.startswith('text/'):
mode = 'r'
else:
mode = 'rb'
try: 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: except IOError:
self.send_error(404, "File not found") self.send_error(404, "File not found")
return None return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment