Closed AndreyMZ closed 2 years ago
Since you did not provide a reproducible code sample, I am trying to understand what is your use case. Are you trying to get a CachedResponse
from a backend manually?
I mean that in the code that you shared
from aiohttp_client_cache import CachedSession
async with CachedSession() as session:
async with session.get("https://example.com/") as response:
content_type = response.content_type # this will work
a ClientResponse
is returned by the context manager and you can access a content_type
.
So I am trying to get into details how your code may look so you access directly CachedResponse
somehow.
I'm able to reproduce it. CachedSession
without a backend
argument uses a non-persistent memory backend by default (since all the "real" backends require optional dependencies), so creating a new one for each request will always return the original response.
This will return a cached response and fail:
async with CachedSession() as session:
async with session.get("https://example.com/") as response:
content_type = response.content_type
async with session.get("https://example.com/") as response:
content_type = response.content_type
It looks like CachedResponse
is missing the properties from HeadersMixin
, including content_type
. I'll fix that.
Fixed in main
. Thanks for the bug report!
The problem
CachedResponse
object has no propertycontent_type
.Expected behavior
CachedResponse
object has propertycontent_type
likeClientResponse
does.Steps to reproduce the behavior
Something like:
Environment
0.6.1
3.9