Permalink
Browse files

reset status code

  • Loading branch information...
1 parent 41c842e commit 5ce60584ad667785bdb81c5a208202a43ed0c91d os0x committed Aug 23, 2011
Showing with 19 additions and 7 deletions.
  1. +3 −1 spec/integration/session_spec.rb
  2. +2 −1 src/Reset.cpp
  3. +12 −5 src/WebPage.cpp
  4. +2 −0 src/WebPage.h
@@ -79,12 +79,14 @@
subject.click_button('ボタン')
end
end
+
context "status code" do
before(:all) do
@app = lambda do |env|
params = ::Rack::Utils.parse_query(env['QUERY_STRING'])
if params["img"] == "true"
- return [404, { 'Content-Type' => 'image/gif', 'Content-Length' => '0' }, ['not found']]
+ body = 'not found'
+ return [404, { 'Content-Type' => 'image/gif', 'Content-Length' => body.length.to_s }, [body]]
end
body = <<-HTML
<html>
View
@@ -11,8 +11,9 @@ void Reset::start(QStringList &arguments) {
page()->triggerAction(QWebPage::Stop);
page()->currentFrame()->setHtml("<html><body></body></html>");
page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
- page()->setNetworkAccessManager(new NetworkAccessManager());
+ page()->setCustomNetworkAccessManager();
page()->setUserAgent(NULL);
+ page()->resetLastStatus();
emit finished(new Response(true));
}
View
@@ -9,17 +9,20 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
setUserStylesheet();
m_loading = false;
-
- NetworkAccessManager *manager = new NetworkAccessManager();
- this->setNetworkAccessManager(manager);
- connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
+ this->setCustomNetworkAccessManager();
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
connect(this, SIGNAL(frameCreated(QWebFrame *)),
this, SLOT(frameCreated(QWebFrame *)));
}
+void WebPage::setCustomNetworkAccessManager() {
+ NetworkAccessManager *manager = new NetworkAccessManager();
+ this->setNetworkAccessManager(manager);
+ connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
+}
+
void WebPage::loadJavascript() {
QResource javascript(":/capybara.js");
if (javascript.isCompressed()) {
@@ -168,7 +171,7 @@ QString WebPage::getLastAttachedFileName() {
}
void WebPage::replyFinished(QNetworkReply *reply) {
- if (reply->url() == this->mainFrame()->url()) {
+ if (reply->url() == this->currentFrame()->url()) {
QStringList headers;
lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QList<QByteArray> list = reply->rawHeaderList();
@@ -186,6 +189,10 @@ int WebPage::getLastStatus() {
return lastStatus;
}
+void WebPage::resetLastStatus() {
+ lastStatus = 0;
+}
+
QString WebPage::pageHeaders() {
return m_pageHeaders;
}
View
@@ -11,6 +11,8 @@ class WebPage : public QWebPage {
QString userAgentForUrl(const QUrl &url ) const;
void setUserAgent(QString userAgent);
int getLastStatus();
+ void resetLastStatus();
+ void setCustomNetworkAccessManager();
bool render(const QString &fileName);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);

0 comments on commit 5ce6058

Please sign in to comment.