File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -199,6 +199,19 @@ def _check_file_path_is_valid(file_path: str) -> bool:
199199 if part == ".." :
200200 raise ParentDirectoryReferenceError (file_path )
201201
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+
202215 @staticmethod
203216 def _get_file_length (file_path : str ) -> int :
204217 """
@@ -213,7 +226,7 @@ def _get_file_length(file_path: str) -> int:
213226 def send_file ( # pylint: disable=too-many-arguments
214227 self ,
215228 filename : str = "index.html" ,
216- root_path : str = "./" ,
229+ root_path : str = None ,
217230 buffer_size : int = 1024 ,
218231 head_only : bool = False ,
219232 safe : bool = True ,
@@ -230,12 +243,8 @@ def send_file( # pylint: disable=too-many-arguments
230243 if safe :
231244 self ._check_file_path_is_valid (filename )
232245
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 )
239248
240249 file_length = self ._get_file_length (full_file_path )
241250
You can’t perform that action at this time.
0 commit comments