Skip to content

Commit

Permalink
Merge pull request #17072 from mvdbeek/add_head_route_to_job_files
Browse files Browse the repository at this point in the history
[23.1] Add HEAD route to job_files endpoint
  • Loading branch information
martenson authored Nov 27, 2023
2 parents c3dbf7d + 11f1b4f commit 4a7dbe9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit 4a7dbe9

Please sign in to comment.