jazzband / django-downloadview

Serve files with Django.
https://django-downloadview.readthedocs.io
Other
374 stars 57 forks source link

HTTPDownloadView: Accept relative url. #126

Closed ryneeverett closed 4 years ago

ryneeverett commented 8 years ago

I want to use HTTPDownloadView to proxy to assets on the same domain. This doesn't seem to be a conventional choice, but I don't like any of the other views for my particular use case -- my django-downloadview's are redirecting solely on the basis of requested url and I don't think exposing the path or object id to end users would be ideal.

HTTPDownloadView passes it's url to the requests library, which expects a fully qualified url. However, ProxiedDownloadMiddleware depends upon that url being the same one in DOWNLOADVIEW_RULES. So in order to use HTTPDownloadView, DOWNLOAD_RULES must also contain fully qualified urls. I don't like this option much because I'd have to modify DOWNLOAD_RULES at startup time to account for different environments (dev, staging, production, etc).

The solution I propose is to construct a fully qualified url to pass to requests while leaving the file.url relative.

It would be nice to add a test for this but it isn't obvious to me where it should go and I wont bother if the proposal is rejected.