default mime type
This commit is contained in:
parent
5e0193d149
commit
981a0ee2ec
2 changed files with 4 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
# GPL 2011
|
# GPL 2011
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import cookielib
|
import cookielib
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
|
@ -8,12 +8,14 @@ from django.http import HttpResponse, Http404
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def HttpFileResponse(path, content_type=None, filename=None):
|
def HttpFileResponse(path, content_type=None, filename=None):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise Http404
|
raise Http404
|
||||||
if not content_type:
|
if not content_type:
|
||||||
content_type = mimetypes.guess_type(path)[0]
|
content_type = mimetypes.guess_type(path)[0]
|
||||||
|
if not content_type:
|
||||||
|
content_type = 'application/octet-stream'
|
||||||
|
|
||||||
if getattr(settings, 'XACCELREDIRECT', False):
|
if getattr(settings, 'XACCELREDIRECT', False):
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
response['Content-Length'] = os.stat(path).st_size
|
response['Content-Length'] = os.stat(path).st_size
|
||||||
|
|
Loading…
Reference in a new issue