mirror of
https://github.com/jazzband/django-downloadview.git
synced 2026-03-16 22:40:25 +00:00
HTTPFile has 'content_type' property. It makes HTTPDownloadView proxy Content-Type header. Closes #116
This commit is contained in:
commit
0c445389f7
5 changed files with 27 additions and 0 deletions
|
|
@ -12,6 +12,9 @@ future releases, check `milestones`_ and :doc:`/about/vision`.
|
|||
|
||||
- Feature #113 - Introduced support of Python 3.5.
|
||||
|
||||
- Feature #116 - ``HTTPFile`` has ``content_type`` property. It makes
|
||||
``HTTPDownloadView`` proxy ``Content-Type`` header from remote location.
|
||||
|
||||
|
||||
1.8 (2015-07-20)
|
||||
----------------
|
||||
|
|
|
|||
|
|
@ -14,3 +14,13 @@ class SimpleURLTestCase(django.test.TestCase):
|
|||
content='Hello world!\n',
|
||||
basename='hello-world.txt',
|
||||
mime_type='text/plain')
|
||||
|
||||
|
||||
class AvatarTestCase(django.test.TestCase):
|
||||
def test_download_response(self):
|
||||
"""HTTPDownloadView proxies Content-Type header."""
|
||||
url = reverse('http:avatar_url')
|
||||
response = self.client.get(url)
|
||||
assert_download_response(self,
|
||||
response,
|
||||
mime_type='image/png')
|
||||
|
|
|
|||
|
|
@ -8,4 +8,7 @@ urlpatterns = patterns(
|
|||
url(r'^simple_url/$',
|
||||
views.simple_url,
|
||||
name='simple_url'),
|
||||
url(r'^avatar_url/$',
|
||||
views.avatar_url,
|
||||
name='avatar_url'),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,4 +10,10 @@ class SimpleURLDownloadView(HTTPDownloadView):
|
|||
'/demo/demoproject/download/fixtures/hello-world.txt'
|
||||
|
||||
|
||||
class GithubAvatarDownloadView(HTTPDownloadView):
|
||||
def get_url(self):
|
||||
return 'https://avatars0.githubusercontent.com/u/235204'
|
||||
|
||||
|
||||
simple_url = SimpleURLDownloadView.as_view()
|
||||
avatar_url = GithubAvatarDownloadView.as_view()
|
||||
|
|
|
|||
|
|
@ -256,3 +256,8 @@ class HTTPFile(File):
|
|||
|
||||
"""
|
||||
return self.request.headers['Content-Length']
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
"""Return content type of the file (from original response)."""
|
||||
return self.request.headers['Content-Type']
|
||||
|
|
|
|||
Loading…
Reference in a new issue