requests-cache / aiohttp-client-cache

An async persistent cache for aiohttp requests
MIT License
122 stars 22 forks source link

aiohttp handles redirect, but aiohttp-client-cache does not #94

Closed simon-liebehenschel closed 3 years ago

simon-liebehenschel commented 3 years ago

The problem

aiohttp handles redirect, but aiohttp-client-cache does not when requesting bytes.

Expected behavior

Read bytes after redirect, as aiohttp do.

Steps to reproduce the behavior

import asyncio

from aiohttp_client_cache import CachedSession, SQLiteBackend

cache = SQLiteBackend()

async def test_stream():
    async with CachedSession(cache=cache) as session:
        response = await session.get("https://file-examples.com/wp-content/uploads/2017/10/file_example_JPG_2500kB.jpg")
        print("From cache:", response.from_cache)

        response_bytes = b""
        while chunk := await response.content.readany():
            print("Chunk:", chunk)
            response_bytes += chunk
        print("Complete response body:", response_bytes)

async def main():
    await cache.clear()
    await test_stream()
    await test_stream()

if __name__ == "__main__":
    asyncio.run(main())

It will print:

From cache: False
Complete response body: b''
From cache: False
Complete response body: b''

Workarounds

I do not know

Environment

JWCook commented 3 years ago

Looks like the fix for #95 also fixed this one. Thanks!

simon-liebehenschel commented 3 years ago

Fixed. Thank you.