Skip to content
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
13 changes: 13 additions & 0 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def test_head_root_index(app):
assert get_response.headers['content-type'] == head_response.headers['content-type']


def test_head_bucket_root_index(app):
# GET /{bucket}/ negotiates browse HTML vs XML listing; HEAD must match
with TestClient(app) as client:
for accept in ["text/html", "application/xml"]:
head_response = client.head("/local-files/", headers={"Accept": accept})
assert head_response.status_code == 200
assert head_response.headers['content-type'].startswith(accept)
assert head_response.headers['vary'] == "Accept"
get_response = client.get("/local-files/", headers={"Accept": accept})
assert get_response.status_code == head_response.status_code
assert get_response.headers['content-type'] == head_response.headers['content-type']


def test_get_object(app):
with TestClient(app) as client:
response = client.get("/local-files/README.md")
Expand Down
7 changes: 6 additions & 1 deletion x2s3/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,12 @@ async def head_object(request: Request, path: str):
# requires s3:ListBucket in real S3
if not target_config.browseable:
return Response(status_code=403, media_type="application/xml")
return Response(status_code=200, media_type="application/xml")
# GET serves the browse UI or an XML listing here depending
# on Accept, so HEAD must report the matching content type
media_type = "text/html" if app.settings.ui and _prefers_html(request) \
else "application/xml"
return Response(status_code=200, media_type=media_type,
headers={"Vary": "Accept"})

response = await client.head_object(target_path)
if response.status_code == 404 and not target_config.browseable:
Expand Down
Loading