Ticket #5596: static.diff
File static.diff, 2.8 KB (added by , 17 years ago) |
---|
-
django/core/servers/basehttp.py
399 399 self.bytes_sent += len(data) 400 400 401 401 # XXX check Content-Length and truncate if too many bytes written? 402 403 # if data is too large, socket will choke, so transfer smaller chunks 404 length = len(data) 405 if length > 33554432: 406 offset = 0 407 while length > 0: 408 chunk_size = min(33554432, length) 409 self._write(data[offset:offset+chunk_size]) 410 self._flush() 411 offset += chunk_size 412 length -= chunk_size 413 return 402 414 self._write(data) 403 415 self._flush() 404 416 -
django/views/static.py
51 51 if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'), 52 52 statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]): 53 53 return HttpResponseNotModified() 54 mimetype = mimetypes.guess_type(fullpath)[0] 54 mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream' 55 55 contents = open(fullpath, 'rb').read() 56 56 response = HttpResponse(contents, mimetype=mimetype) 57 57 response["Last-Modified"] = rfc822.formatdate(statobj[stat.ST_MTIME]) 58 response["Content-Length"] = len(contents) 58 59 return response 59 60 60 61 DEFAULT_DIRECTORY_INDEX_TEMPLATE = """ -
tests/regressiontests/views/media/file.unknown
1 An unknown file extension. -
tests/regressiontests/views/tests/static.py
12 12 for filename in media_files: 13 13 response = self.client.get('/views/site_media/%s' % filename) 14 14 file = open(path.join(media_dir, filename)) 15 self.assertEquals(file.read(), response.content) 16 No newline at end of file 15 self.assertEquals(file.read(), response.content) 16 self.assertEquals(len(response.content), response['Content-Length']) 17 18 def test_unknown_mime_type(self): 19 response = self.client.get('/views/site_media/file.unknown') 20 self.assertEquals('application/octet-stream', response['Content-Type'])