jeanphix/Ghost.py — pull request #79 by arikfr (2013-03-24 16:09:20+00:00)
Title: Fix: pages with "no-cache" headers returned with no content

This pull request fixes two issues:

**1. Pages with "no-cache" headers returned with no content**

Because we retrieve the resources content from the cache object, when opening pages that have a "no-cache" header the page resource will be empty (for real life example see: [Etsy](http://www.etsy.com); I've also added a test case for this).

To fix this, I've applied a small workaround:
When the `finished` signal is called, I check the `bytesAvailable` size of the reply object -- if it's 0, this means the object was already read by the cache and we do nothing. Otherwise, I use peek (which allows other callers to get access to the reply data) to read the content.

This is very hackish workaround and I suspect it might not always work properly, because of the async nature of Qt. I started exploring other options, like subclassing `QNetworkAccessManager` but had issues with subclassing `QNetworkReply`, and therefore left the solution as is for now.

**2. Tests fail when run with PyQt rather than PySide**

Some of the tests fail when run with PyQt, and that's because `HttpResource.url` is a QString for PySide, but QUrl for PyQt. I've changed it to be a QString for both implementations and do a different call to `cache.data` rather than storing different type to `url`.