1
- import copy
2
1
import mimetypes
3
2
from urllib .parse import parse_qsl , urlencode , urlparse
4
3
@@ -233,22 +232,17 @@ def _serve_file_from_nginx(self, path, root_path):
233
232
:param path: The path of the file to serve.
234
233
:param root_path: The root path of the internal redirect.
235
234
"""
236
- original_path = copy .copy (path )
237
- if not path .startswith (f"/{ root_path } /" ):
238
- if path [0 ] == "/" :
239
- path = path [1 :]
240
- path = f"/{ root_path } /{ path } "
241
-
235
+ internal_path = f"/{ root_path } /" + path .lstrip ("/" )
242
236
log .debug (
243
237
"Nginx serve." ,
244
- original_path = original_path ,
245
- path = path ,
238
+ original_path = path ,
239
+ internal_path = internal_path ,
246
240
)
247
241
248
- content_type , encoding = mimetypes .guess_type (path )
242
+ content_type , encoding = mimetypes .guess_type (internal_path )
249
243
content_type = content_type or "application/octet-stream"
250
244
response = HttpResponse (
251
- f"Serving internal path: { path } " , content_type = content_type
245
+ f"Serving internal path: { internal_path } " , content_type = content_type
252
246
)
253
247
if encoding :
254
248
response ["Content-Encoding" ] = encoding
@@ -258,11 +252,11 @@ def _serve_file_from_nginx(self, path, root_path):
258
252
# as the header value.
259
253
# https://github.com/benoitc/gunicorn/issues/1448
260
254
# https://docs.djangoproject.com/en/1.11/ref/unicode/#uri-and-iri-handling
261
- x_accel_redirect = iri_to_uri (path )
255
+ x_accel_redirect = iri_to_uri (internal_path )
262
256
response ["X-Accel-Redirect" ] = x_accel_redirect
263
257
264
258
# Needed to strip any GET args, etc.
265
- response .proxito_path = urlparse (path ).path
259
+ response .proxito_path = urlparse (internal_path ).path
266
260
return response
267
261
268
262
def _serve_file_from_python (self , request , path , storage ):
0 commit comments