Browse Source

fix #642: remove sendfile facilities

Rafał Pitoń 8 years ago
parent
commit
0be1c1bf3b

+ 0 - 22
docs/developers/settings.rst

@@ -382,28 +382,6 @@ Standard configs as of PostgreSQL 9.5 are: ``dutch``, ``english``, ``finnish``,
    Items in Misago are usually indexed in search engine on save or update. If you change search configuration, you'll need to rebuild search for past posts to get reindexed using new configuration. Misago comes with ``rebuildpostssearch`` tool for this purpose.
 
 
-MISAGO_SENDFILE_HEADER
-----------------------
-
-If your server provides proxy for serving files from application, like "X-Sendfile", set its header name in this setting.
-
-Leave this setting empty to use Django fallback.
-
-
-MISAGO_SENDFILE_LOCATIONS_PATH
-------------------------------
-
-Some Http servers (like Nginx) allow you to restrict X-Sendfile to certain locations.
-
-Misago supports this feature with this setting, however with limitation to one "root" path. This setting is used for paths defined in ATTACHMENTS_ROOT and AVATAR_CACHE settings.
-
-Rewrite algorithm used by Misago replaces path until last part with value of this setting.
-
-For example, defining ``MISAGO_SENDFILE_LOCATIONS_PATH = 'misago_served_internals'`` will result in following rewrite:
-
-``/home/mysite/www/attachments/13_05/142123.rar`` => ``/misago_served_internals/attachments/13_05/142123.rar``
-
-
 MISAGO_STOP_FORUM_SPAM_USE
 --------------------------
 

+ 0 - 17
misago/conf/defaults.py

@@ -323,23 +323,6 @@ MISAGO_USERS_PER_PAGE = 12
 MISAGO_READTRACKER_CUTOFF = 40
 
 
-# X-Sendfile
-# X-Sendfile is feature provided by Http servers that allows web apps to
-# delegate serving files over to the better performing server instead of
-# doing it within app.
-# If your server supports X-Sendfile or its variation, enter header name here.
-# For example if you are using Nginx with X-accel enabled, set this setting
-# to "X-Accel-Redirect".
-# Leave this setting empty to Django fallback instead
-MISAGO_SENDFILE_HEADER = ''
-
-# Allows you to use location feature of your Http server
-# For example, if you have internal location /mymisago/avatar_cache/
-# that points at /home/myweb/misagoforum/avatar_cache/, set this setting
-# to "mymisago".
-MISAGO_SENDFILE_LOCATIONS_PATH = ''
-
-
 # Default forms templates
 CRISPY_TEMPLATE_PACK = 'bootstrap3'
 

+ 0 - 49
misago/core/fileserver.py

@@ -1,49 +0,0 @@
-import os
-
-from django.conf import settings
-from django.http import HttpResponse, StreamingHttpResponse
-
-
-SERVED_PATHS = ()
-
-
-def make_file_response(file_path, content_type, attachment=None):
-    file_size = os.path.getsize(file_path)
-
-    response_args = (file_path, content_type, file_size, attachment)
-    if settings.MISAGO_SENDFILE_HEADER:
-        return make_header_response(*response_args)
-    else:
-        return make_stream_response(*response_args)
-
-
-def make_header_response(file_path, content_type, file_size, attachment=None):
-    if settings.MISAGO_SENDFILE_LOCATIONS_PATH:
-        file_path = rewrite_file_path(file_path)
-
-    response = HttpResponse()
-    response[settings.MISAGO_SENDFILE_HEADER] = file_path
-    del response['Content-Type']
-
-    return response
-
-
-def rewrite_file_path(file_path):
-    for path in SERVED_PATHS:
-        if file_path.startswith(path):
-            suffix = file_path[len(path):]
-            return '/%s%s' % (settings.MISAGO_SENDFILE_LOCATIONS_PATH, suffix)
-    else:
-        raise ValueError("'%s' path is not supported" % file_path)
-
-
-def make_stream_response(file_path, content_type, file_size, attachment=None):
-    response = StreamingHttpResponse(open(file_path, 'rb'))
-
-    response['Content-Type'] = content_type
-    response['Content-Length'] = file_size
-    if attachment:
-        header = 'attachment; filename="%s"' % attachment
-        response['Content-Disposition'] = header
-
-    return response

+ 0 - 41
misago/core/tests/test_fileserver.py

@@ -1,41 +0,0 @@
-from django.conf import settings
-from django.http import HttpResponse, StreamingHttpResponse
-from django.test import TestCase
-
-from .. import fileserver
-
-
-class FileServerTests(TestCase):
-    def test_send_file(self):
-        """send file produces valid response"""
-        with self.settings(MISAGO_SENDFILE_HEADER='X-Test'):
-            response = fileserver.make_file_response(__file__, 'text/python')
-            self.assertTrue(isinstance(response, HttpResponse))
-            self.assertEqual(response['X-Test'], __file__)
-
-        with self.settings(MISAGO_SENDFILE_HEADER=''):
-            response = fileserver.make_file_response(__file__, 'text/python')
-            self.assertTrue(isinstance(response, StreamingHttpResponse))
-
-    def test_rewrite_file_path(self):
-        """file paths are rewritten"""
-        with self.settings(MISAGO_SENDFILE_LOCATIONS_PATH='mymisagopath'):
-            test_path = '%s/somefile.png' % settings.MISAGO_AVATAR_STORE
-            rewritten_path = fileserver.rewrite_file_path(test_path)
-            self.assertTrue(rewritten_path.startswith('/mymisagopath/'))
-
-            with self.assertRaises(ValueError):
-                fileserver.rewrite_file_path('some/non_rewrriten/path.zip')
-
-    def test_send_header(self):
-        """call to header response function returns HttpResponse"""
-        with self.settings(MISAGO_SENDFILE_HEADER='X-Test'):
-            response = fileserver.make_header_response(
-                __file__, 'text/python', 9)
-            self.assertTrue(isinstance(response, HttpResponse))
-            self.assertEqual(response['X-Test'], __file__)
-
-    def test_send_stream(self):
-        """call to streaming response function returns StreamingHttpResponse"""
-        response = fileserver.make_stream_response(__file__, 'text/python', 9)
-        self.assertTrue(isinstance(response, StreamingHttpResponse))