File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,19 @@ def _check_file_path_is_valid(file_path: str) -> bool:
199
199
if part == ".." :
200
200
raise ParentDirectoryReferenceError (file_path )
201
201
202
+ @staticmethod
203
+ def _combine_path (root_path : str , filename : str ) -> str :
204
+ """
205
+ Combines ``root_path`` and ``filename`` into a single path.
206
+ """
207
+
208
+ if not root_path .endswith ("/" ):
209
+ root_path += "/"
210
+ if filename .startswith ("/" ):
211
+ filename = filename [1 :]
212
+
213
+ return root_path + filename
214
+
202
215
@staticmethod
203
216
def _get_file_length (file_path : str ) -> int :
204
217
"""
@@ -213,7 +226,7 @@ def _get_file_length(file_path: str) -> int:
213
226
def send_file ( # pylint: disable=too-many-arguments
214
227
self ,
215
228
filename : str = "index.html" ,
216
- root_path : str = "./" ,
229
+ root_path : str = None ,
217
230
buffer_size : int = 1024 ,
218
231
head_only : bool = False ,
219
232
safe : bool = True ,
@@ -230,12 +243,8 @@ def send_file( # pylint: disable=too-many-arguments
230
243
if safe :
231
244
self ._check_file_path_is_valid (filename )
232
245
233
- if not root_path .endswith ("/" ):
234
- root_path += "/"
235
- if filename .startswith ("/" ):
236
- filename = filename [1 :]
237
-
238
- full_file_path = root_path + filename
246
+ root_path = root_path or self .request .server .root_path
247
+ full_file_path = self ._combine_path (root_path , filename )
239
248
240
249
file_length = self ._get_file_length (full_file_path )
241
250
You can’t perform that action at this time.
0 commit comments