Priority: P2: Important
Affects Version/s: 5.3.1, 5.3.2
Fix Version/s: None
Component/s: Network: Cache
When using a QNetworkDiskCache with setMaximumCacheSize called, and then doing a request with a QNetworkAccessManager twice, the second time (cached) I don't get the data I'd expect but corrupt data instead.
Looking at wireshark, this is what happens:
- Qt sends a request, in my case to http://winhelp2002.mvps.org/hosts.txt
- The server returns the content
- Qt sends the second request, with an "If-Modified-Since" header.
- The server sends "304 not modified" back.
- Qt reads the content from the cache, but if I call readAll on the QNetworkReply, I always get the hex bytes 00 00 00 04 00 00 00 00 instead of the few kilobytes of data I'd expect.
Attached are two examples: A minimal PyQt5/Python3 example, and the Qt HTTP example with a cache hacked in. With the latter, the bug can be seen by downloading http://winhelp2002.mvps.org/hosts.txt twice, and then looking at the downloaded file.
(Note: For the C++ example, the cache is hardcoded in /tmp/qtbug-cache and doesn't get deleted automatically - this is the first time I'm doing something in C++, and I don't want to mess with deleting stuff until I feel like I know what I'm doing)
What I observed so far:
- It doesn't happen on Windows 8
- It doesn't happen when the cache size is over a certain limit. For me, it happens with a cache size of 561 kilobytes, and goes away with 562 kilobytes.
- It doesn't happen when calling setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork) on the request.
- Why doesn't this seem to affect QtWebKit?
- Is there a suitable workaround except disabling the cache for all manual requests?