diff --git a/simple_repository_server/__main__.py b/simple_repository_server/__main__.py index 05b8729..704b612 100644 --- a/simple_repository_server/__main__.py +++ b/simple_repository_server/__main__.py @@ -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 diff --git a/simple_repository_server/tests/test__http_response_iterator.py b/simple_repository_server/tests/test__http_response_iterator.py index 11b206c..a981048 100644 --- a/simple_repository_server/tests/test__http_response_iterator.py +++ b/simple_repository_server/tests/test__http_response_iterator.py @@ -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