Skip to content

Commit

Permalink
Adapt to upstream FileResponse logic
Browse files Browse the repository at this point in the history
The ``send_header_only`` attribute has been removed in starlette
(encode/starlette#2366), and replaced with
`scope["method"].upper() == "HEAD"`
  • Loading branch information
mvdbeek committed Jan 30, 2024
1 parent 42e0222 commit 9c379b7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/galaxy/webapps/base/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,11 @@ def __init__(
path, status_code, headers, media_type, background, filename, stat_result, method, content_disposition_type
)
self.headers["accept-ranges"] = "bytes"
send_header_only = self.nginx_x_accel_redirect_base or self.apache_xsendfile
self.send_header_only = 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:
self.headers["x-sendfile"] = os.path.abspath(path)
if not self.send_header_only and send_header_only:
# 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"

async def __call__(self, scope: "Scope", receive: "Receive", send: "Send") -> None:
if self.stat_result is None:
Expand All @@ -100,9 +96,14 @@ 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:
# 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"

start = 0
end = stat_result.st_size - 1
if not self.send_header_only:
if not scope["method"].upper() == "HEAD":
http_range = ""
for key, value in scope["headers"]:
if key == b"range":
Expand Down

0 comments on commit 9c379b7

Please sign in to comment.