|
9 | 9 | import shutil |
10 | 10 | from sendfile import sendfile as real_sendfile, _get_sendfile |
11 | 11 |
|
| 12 | +try: |
| 13 | + from urllib.parse import unquote |
| 14 | +except ImportError: |
| 15 | + from urllib import unquote |
| 16 | + |
12 | 17 |
|
13 | 18 | def sendfile(request, filename, **kwargs): |
14 | 19 | # just a simple response with the filename |
@@ -127,4 +132,26 @@ def test_xaccelredirect_header_containing_unicode(self): |
127 | 132 | filepath = self.ensure_file(u'péter_là_gueule.txt') |
128 | 133 | response = real_sendfile(HttpRequest(), filepath) |
129 | 134 | self.assertTrue(response is not None) |
130 | | - self.assertEqual(u'/private/péter_là_gueule.txt'.encode('utf-8'), response['X-Accel-Redirect']) |
| 135 | + self.assertEqual(u'/private/péter_là_gueule.txt'.encode('utf-8'), unquote(response['X-Accel-Redirect'])) |
| 136 | + |
| 137 | + |
| 138 | +class TestModWsgiBackend(TempFileTestCase): |
| 139 | + |
| 140 | + def setUp(self): |
| 141 | + super(TestModWsgiBackend, self).setUp() |
| 142 | + settings.SENDFILE_BACKEND = 'sendfile.backends.mod_wsgi' |
| 143 | + settings.SENDFILE_ROOT = self.TEMP_FILE_ROOT |
| 144 | + settings.SENDFILE_URL = '/private' |
| 145 | + _get_sendfile.clear() |
| 146 | + |
| 147 | + def test_correct_url_in_location_header(self): |
| 148 | + filepath = self.ensure_file('readme.txt') |
| 149 | + response = real_sendfile(HttpRequest(), filepath) |
| 150 | + self.assertTrue(response is not None) |
| 151 | + self.assertEqual('/private/readme.txt', response['Location']) |
| 152 | + |
| 153 | + def test_location_header_containing_unicode(self): |
| 154 | + filepath = self.ensure_file(u'péter_là_gueule.txt') |
| 155 | + response = real_sendfile(HttpRequest(), filepath) |
| 156 | + self.assertTrue(response is not None) |
| 157 | + self.assertEqual(u'/private/péter_là_gueule.txt'.encode('utf-8'), unquote(response['Location'])) |
0 commit comments