Skip to content

Commit

Permalink
Define variables
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Soranzo <[email protected]>
  • Loading branch information
mvdbeek and nsoranzo committed Jan 30, 2024
1 parent e9d7b18 commit d08044c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/galaxy/webapps/base/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class GalaxyFileResponse(FileResponse):

nginx_x_accel_redirect_base: typing.Optional[str] = None
apache_xsendfile: typing.Optional[bool] = None
send_header_only: bool

def __init__(
self,
Expand All @@ -77,7 +76,7 @@ def __init__(
path, status_code, headers, media_type, background, filename, stat_result, method, content_disposition_type
)
self.headers["accept-ranges"] = "bytes"
self.send_header_only = self.nginx_x_accel_redirect_base or self.apache_xsendfile
self.xsendfile = self.nginx_x_accel_redirect_base or self.apache_xsendfile
if self.nginx_x_accel_redirect_base:
self.headers["x-accel-redirect"] = self.nginx_x_accel_redirect_base + os.path.abspath(path)
elif self.apache_xsendfile:
Expand All @@ -96,14 +95,15 @@ async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> No
raise RuntimeError(f"File at path {self.path} is not a file.")

# This is where we diverge from the superclass, this adds support for byte range requests
if not scope["method"].upper() == "HEAD" and self.send_header_only:
is_head_request = scope["method"].upper() == "HEAD"
if not is_head_request and self.xsendfile:
# Not a head request, but nginx_x_accel_redirect_base / send_header_only, we don't send a body
self.send_header_only = True
self.headers["content-length"] = "0"
send_header_only = self.xsendfile or is_head_request

start = 0
end = stat_result.st_size - 1
if not scope["method"].upper() == "HEAD":
if not send_header_only:
http_range = ""
for key, value in scope["headers"]:
if key == b"range":
Expand All @@ -121,7 +121,7 @@ async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> No
"headers": self.raw_headers,
}
)
if self.send_header_only:
if send_header_only:
await send({"type": "http.response.body", "body": b"", "more_body": False})
else:
# This also diverges from the superclass by seeking to start and limiting to end if handling byte range requests
Expand Down

0 comments on commit d08044c

Please sign in to comment.