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
2 changes: 1 addition & 1 deletion simple_repository_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def lifespan(app: FastAPI) -> typing.AsyncIterator[None]:
logging.info(f"Using netrc authentication from: {netrc_path}")
auth = httpx.NetRCAuth(file=str(netrc_path))

async with httpx.AsyncClient(auth=auth) as http_client:
async with httpx.AsyncClient(auth=auth, follow_redirects=True) as http_client:
repo = create_repository(repository_urls, http_client=http_client)
app.include_router(simple.build_router(repo, http_client=http_client))
yield
Expand Down
30 changes: 30 additions & 0 deletions simple_repository_server/tests/test__http_response_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,33 @@ async def test_http_response_iterator__response_remains_gzipped(
content = b''.join([chunk async for chunk in response_it])
assert len(content) == len(compressed)
assert decoder(content) == input_content


@pytest.mark.asyncio
async def test_http_response_iterator__follows_redirects(
httpserver: HTTPServer,
) -> None:
# Test that the HttpResponseIterator follows redirects properly
final_content = b"This is the final content after redirect"

# Set up redirect chain: /redirect -> /final
httpserver.expect_request('/final').respond_with_data(
final_content,
headers={'content-type': 'application/octet-stream'},
)
httpserver.expect_request('/redirect').respond_with_data(
b"",
status=302,
headers={'location': httpserver.url_for('/final')},
)

http_client = httpx.AsyncClient(follow_redirects=True)
response_it = await HttpResponseIterator.create_iterator(
http_client,
httpserver.url_for('/redirect'),
)

# Should get the final content, not the redirect response
assert response_it.status_code == 200
content = b''.join([chunk async for chunk in response_it])
assert content == final_content
Loading