Ticket #2131: http-response-send-file.diff
File http-response-send-file.diff, 3.0 KB (added by , 18 years ago) |
---|
-
django/http/__init__.py
238 238 raise Exception, "This %s instance cannot tell its position" % self.__class__ 239 239 return sum([len(chunk) for chunk in self._iterator]) 240 240 241 class HttpResponseSendFile(HttpResponse): 242 def __init__(self, path_to_file, content_type=None): 243 HttpResponse.__init__(self) 244 if not content_type: 245 from mimetime import guess_type 246 content_type = guess_type(path_to_file) 247 self['Content-Type'] = content_type 248 self.sendfile_filename = path_to_file 249 self.block_size = 8192 250 self.status_code = 200 251 241 252 class HttpResponseRedirect(HttpResponse): 242 253 def __init__(self, redirect_to): 243 254 HttpResponse.__init__(self) -
django/core/servers/basehttp.py
307 307 in the event loop to iterate over the data, and to call 308 308 'self.close()' once the response is finished. 309 309 """ 310 if not self.result_is_file() and not self.sendfile(): 311 for data in self.result: 312 self.write(data) 313 self.finish_content() 310 for data in self.result: 311 self.write(data) 312 self.finish_content() 314 313 self.close() 315 314 316 315 def get_scheme(self): -
django/core/handlers/wsgi.py
160 160 for c in response.cookies.values(): 161 161 response_headers.append(('Set-Cookie', c.output(header=''))) 162 162 start_response(status, response_headers) 163 if hasattr(response, 'sendfile_filename'): 164 filelike = open(response.sendfile_filename, 'rb') 165 block_size = response.block_size 166 if 'wsgi.file_wrapper' in environ: 167 return environ['wsgi.file_wrapper'](filelike, block_size) 168 else: 169 return iter(lambda: filelike.read(block_size), '') 163 170 return response.iterator -
django/core/handlers/modpython.py
143 143 "Populates the mod_python request object with an HttpResponse" 144 144 from django.conf import settings 145 145 mod_python_req.content_type = http_response['Content-Type'] 146 if hasattr(http_response, 'sendfile_filename'): 147 mod_python_req.sendfile(http_response.sendfile_filename) 148 return 146 149 for key, value in http_response.headers.items(): 147 150 if key != 'Content-Type': 148 151 mod_python_req.headers_out[key] = value