Return unsupported content as plain text

This commit is contained in:
Matthew Horan 2012-11-21 23:20:47 -05:00
parent 3c8ad255ad
commit fbead1ebb5
5 changed files with 45 additions and 1 deletions

View File

@ -257,6 +257,31 @@ describe Capybara::Webkit::Driver do
it "sets the response headers with respect to the unsupported request" do
driver.response_headers["Content-Type"].should == "text/css"
end
it "does not wrap the content in HTML tags" do
driver.html.should_not =~ /<html>/
end
end
context "html app" do
let(:driver) do
driver_for_html(<<-HTML)
<html>
<head>
<title>Hello HTML</title>
</head>
<body>
<h1>This Is HTML!</h1>
</body>
</html>
HTML
end
before { visit("/") }
it "does not strip HTML tags" do
driver.html.should =~ /<html>/
end
end
context "hello app" do

View File

@ -10,6 +10,7 @@ UnsupportedContentHandler::UnsupportedContentHandler(WebPage *page, QNetworkRepl
void UnsupportedContentHandler::renderNonHtmlContent() {
QByteArray text = m_reply->readAll();
m_page->mainFrame()->setContent(text, QString("text/plain"), m_reply->url());
m_page->setUnsupportedContentLoaded();
m_page->networkAccessManagerFinishedReply(m_reply);
m_page->loadFinished(true);
this->deleteLater();

View File

@ -14,6 +14,7 @@ WebPage::WebPage(WebPageManager *manager, QObject *parent) : QWebPage(parent) {
m_failed = false;
m_manager = manager;
m_uuid = QUuid::createUuid().toString();
m_unsupportedContentLoaded = false;
setForwardUnsupportedContent(true);
loadJavascript();
@ -169,6 +170,7 @@ bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const Q
void WebPage::loadStarted() {
m_loading = true;
m_errorPageMessage = QString();
m_unsupportedContentLoaded = false;
}
void WebPage::loadFinished(bool success) {
@ -275,6 +277,14 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
}
}
void WebPage::setUnsupportedContentLoaded() {
m_unsupportedContentLoaded = true;
}
bool WebPage::unsupportedContentLoaded() {
return m_unsupportedContentLoaded;
}
bool WebPage::supportsExtension(Extension extension) const {
if (extension == ErrorPageExtension)
return true;

View File

@ -34,6 +34,8 @@ class WebPage : public QWebPage {
bool matchesWindowSelector(QString);
void setFocus();
NetworkAccessManager *networkAccessManager();
void setUnsupportedContentLoaded();
bool unsupportedContentLoaded();
public slots:
bool shouldInterruptJavaScript();
@ -79,6 +81,7 @@ class WebPage : public QWebPage {
QString m_uuid;
WebPageManager *m_manager;
QString m_errorPageMessage;
bool m_unsupportedContentLoaded;
};
#endif //_WEBPAGE_H

View File

@ -6,6 +6,11 @@ Body::Body(WebPageManager *manager, QStringList &arguments, QObject *parent) : S
}
void Body::start() {
QString result = page()->currentFrame()->toHtml();
QString result;
if (page()->unsupportedContentLoaded())
result = page()->currentFrame()->toPlainText();
else
result = page()->currentFrame()->toHtml();
emit finished(new Response(true, result));
}