Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Treat fewer responses as fatal failures

* Relies on errorExtension instead of loadFinished
* Ignores errors from canceled requests
  • Loading branch information...
commit d8020ce3a4dfc75cfb715c563398cc6e444d601b 1 parent 0942500
@jferris jferris authored
View
15 src/UnsupportedContentHandler.cpp
@@ -10,23 +10,18 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
}
void UnsupportedContentHandler::handleUnsupportedContent() {
- QVariant contentMimeType = m_reply->header(QNetworkRequest::ContentTypeHeader);
- if(contentMimeType.isNull()) {
- this->finish(false);
- } else {
- this->loadUnsupportedContent();
- this->finish(true);
- }
+ this->renderNonHtmlContent();
+ this->finish();
this->deleteLater();
}
-void UnsupportedContentHandler::loadUnsupportedContent() {
+void UnsupportedContentHandler::renderNonHtmlContent() {
QByteArray text = m_reply->readAll();
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
}
-void UnsupportedContentHandler::finish(bool success) {
+void UnsupportedContentHandler::finish() {
connect(m_page, SIGNAL(loadFinished(bool)), m_page, SLOT(loadFinished(bool)));
m_page->networkAccessManagerFinishedReply(m_reply);
- m_page->loadFinished(success);
+ m_page->loadFinished(true);
}
View
4 src/UnsupportedContentHandler.h
@@ -13,6 +13,6 @@ class UnsupportedContentHandler : public QObject {
private:
WebPage *m_page;
QNetworkReply *m_reply;
- void loadUnsupportedContent();
- void finish(bool success);
+ void renderNonHtmlContent();
+ void finish();
};
View
14 src/WebPage.cpp
@@ -11,6 +11,7 @@
WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
m_loading = false;
+ m_failed = false;
m_manager = manager;
m_uuid = QUuid::createUuid().toString();
m_lastStatus = 0;
@@ -162,8 +163,10 @@ void WebPage::loadStarted() {
}
void WebPage::loadFinished(bool success) {
+ Q_UNUSED(success);
m_loading = false;
- emit pageFinished(success);
+ emit pageFinished(!m_failed);
+ m_failed = false;
}
bool WebPage::isLoading() const {
@@ -221,6 +224,7 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
else if (extension == QWebPage::ErrorPageExtension) {
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
m_errorPageMessage = " because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
+ m_failed = true;
return false;
}
return false;
@@ -248,8 +252,12 @@ QString WebPage::pageHeaders() {
}
void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
- UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
- Q_UNUSED(handler);
+ QVariant contentMimeType = reply->header(QNetworkRequest::ContentTypeHeader);
+ if(!contentMimeType.isNull()) {
+ triggerAction(QWebPage::Stop);
+ UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
+ Q_UNUSED(handler);
+ }
}
bool WebPage::supportsExtension(Extension extension) const {
View
1  src/WebPage.h
@@ -57,6 +57,7 @@ class WebPage : public QWebPage {
QString m_capybaraJavascript;
QString m_userAgent;
bool m_loading;
+ bool m_failed;
QString getLastAttachedFileName();
void loadJavascript();
void setUserStylesheet();
Please sign in to comment.
Something went wrong with that request. Please try again.