Ticket #2131: httpresponsesendfile-no-default-content.diff
File httpresponsesendfile-no-default-content.diff, 3.7 KB (added by , 16 years ago) |
---|
-
django/http/__init__.py
393 393 raise Exception("This %s instance cannot tell its position" % self.__class__) 394 394 return sum([len(chunk) for chunk in self._container]) 395 395 396 class HttpResponseSendFile(HttpResponse): 397 def __init__(self, path_to_file, content_type=None, block_size=8192): 398 if not content_type: 399 from mimetypes import guess_type 400 content_type = guess_type(path_to_file)[0] 401 if content_type is None: 402 content_type = "application/octet-stream" 403 super(HttpResponseSendFile, self).__init__(None, 404 content_type=content_type) 405 self.sendfile_filename = path_to_file 406 self.block_size = block_size 407 self._headers['content-length'] = ('Content-Length', 408 os.path.getsize(path_to_file)) 409 396 410 class HttpResponseRedirect(HttpResponse): 397 411 status_code = 302 398 412 -
django/core/servers/basehttp.py
313 313 in the event loop to iterate over the data, and to call 314 314 'self.close()' once the response is finished. 315 315 """ 316 if not self.result_is_file() and not self.sendfile(): 317 for data in self.result: 318 self.write(data) 319 self.finish_content() 316 for data in self.result: 317 self.write(data) 318 self.finish_content() 320 319 self.close() 321 320 322 321 def get_scheme(self): -
django/core/handlers/wsgi.py
252 252 except KeyError: 253 253 status_text = 'UNKNOWN STATUS CODE' 254 254 status = '%s %s' % (response.status_code, status_text) 255 255 256 response_headers = [(str(k), str(v)) for k, v in response.items()] 256 257 for c in response.cookies.values(): 257 258 response_headers.append(('Set-Cookie', str(c.output(header='')))) 259 258 260 start_response(status, response_headers) 261 262 if isinstance(response, http.HttpResponseSendFile): 263 filelike = open(response.sendfile_filename, 'rb') 264 if 'wsgi.file_wrapper' in environ: 265 return environ['wsgi.file_wrapper'](filelike, 266 response.block_size) 267 else: 268 # wraps close() as well 269 from django.core.servers.basehttp import FileWrapper 270 return FileWrapper(filelike, response.block_size) 271 259 272 return response 260 273 -
django/core/handlers/modpython.py
215 215 for c in response.cookies.values(): 216 216 req.headers_out.add('Set-Cookie', c.output(header='')) 217 217 req.status = response.status_code 218 try:219 for chunk in response:220 req.write(chunk)221 finally:222 response.close()223 218 219 if isinstance(response, http.HttpResponseSendFile): 220 req.sendfile(response.sendfile_filename) 221 else: 222 try: 223 for chunk in response: 224 req.write(chunk) 225 finally: 226 response.close() 227 224 228 return 0 # mod_python.apache.OK 225 229 226 230 def handler(req):