def get(self, request, name):
db_file = get_object_or_404(DBFile.objects.defer('content'), name=name)
mtime = time.mktime(db_file.updated_on.timetuple())
modified = was_modified_since(
header=self.request.META.get('HTTP_IF_MODIFIED_SINCE'),
mtime=mtime,
size=db_file.size)
if not modified:
return HttpResponseNotModified()
content_type, encoding = mimetypes.guess_type(db_file.name)
content_type = content_type or 'application/octet-stream'
response = HttpResponse(db_file.content, content_type=content_type)
response['Last-Modified'] = http_date(mtime)
response['Content-Length'] = db_file.size
if encoding: response['Content-Encoding'] = encoding
return response
评论列表
文章目录