Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23.1] Add HEAD route to job_files endpoint #17072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/galaxy/web/framework/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,18 @@ def send_file(start_response, trans, body):
trans.response.headers["accept-ranges"] = "bytes"
start = None
end = None
if trans.request.method == "HEAD":
trans.response.headers["content-length"] = os.path.getsize(body.name)
body = b""
if trans.request.range:
start = int(trans.request.range.start)
file_size = int(trans.response.headers["content-length"])
end = int(file_size if end is None else trans.request.range.end)
trans.response.headers["content-length"] = str(end - start)
trans.response.headers["content-range"] = f"bytes {start}-{end - 1}/{file_size}"
trans.response.status = 206
body = iterate_file(body, start, end)
if body:
body = iterate_file(body, start, end)
start_response(trans.response.wsgi_status(), trans.response.wsgi_headeritems())
return body

Expand Down
8 changes: 8 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,14 @@ def connect_invocation_endpoint(endpoint_name, endpoint_suffix, action, conditio
parent_resources=dict(member_name="job", collection_name="jobs"),
)

webapp.mapper.connect(
"index",
"/api/jobs/{job_id}/files",
controller="job_files",
action="index",
conditions=dict(method=["HEAD"]),
)

webapp.mapper.resource(
"port",
"ports",
Expand Down
4 changes: 4 additions & 0 deletions test/integration/test_job_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def test_read_by_state(self):
job_id, job_key = self._api_job_keys(job)
data = {"path": self.input_hda.file_name, "job_key": job_key}
get_url = self._api_url(f"jobs/{job_id}/files", use_key=True)
head_response = requests.head(get_url, params=data)
api_asserts.assert_status_code_is_ok(head_response)
assert head_response.text == ""
assert head_response.headers["content-length"] == str(len(TEST_INPUT_TEXT))
response = requests.get(get_url, params=data)
api_asserts.assert_status_code_is_ok(response)
assert response.text == TEST_INPUT_TEXT
Expand Down
Loading