From b6ec5066b044160706f52b42df24ee6bdbe57b1f Mon Sep 17 00:00:00 2001 From: Marius van den Beek Date: Tue, 30 Jan 2024 17:30:57 +0100 Subject: [PATCH] Define variables Co-authored-by: Nicola Soranzo --- lib/galaxy/webapps/base/api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/webapps/base/api.py b/lib/galaxy/webapps/base/api.py index 61669defb88d..77aeec873977 100644 --- a/lib/galaxy/webapps/base/api.py +++ b/lib/galaxy/webapps/base/api.py @@ -77,7 +77,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: @@ -96,14 +96,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":