Permalink
Browse files

Merge in upstream status code and header changes.

  • Loading branch information...
1 parent 78ca26a commit 585fbbc99de72126c21764a647ff4b00d64be7b2 @tristandunn committed Aug 20, 2011
Showing with 83 additions and 3 deletions.
  1. +2 −0 src/Connection.cpp
  2. +11 −0 src/Headers.cpp
  3. +12 −0 src/Headers.h
  4. +13 −0 src/Status.cpp
  5. +12 −0 src/Status.h
  6. +24 −1 src/WebPage.cpp
  7. +5 −0 src/WebPage.h
  8. +2 −0 src/find_command.h
  9. +2 −2 src/webkit_server.pro
View
@@ -13,6 +13,8 @@
#include "Header.h"
#include "Render.h"
#include "Body.h"
+#include "Status.h"
+#include "Headers.h"
#include <QTcpSocket>
#include <iostream>
View
@@ -0,0 +1,11 @@
+#include "Headers.h"
+#include "WebPage.h"
+
+Headers::Headers(WebPage *page, QObject *parent) : Command(page, parent) {
+}
+
+void Headers::start(QStringList &arguments) {
+ Q_UNUSED(arguments);
+ emit finished(new Response(true, page()->pageHeaders()));
+}
+
View
@@ -0,0 +1,12 @@
+#include "Command.h"
+
+class WebPage;
+
+class Headers : public Command {
+ Q_OBJECT
+
+ public:
+ Headers(WebPage *page, QObject *parent = 0);
+ virtual void start(QStringList &arguments);
+};
+
View
@@ -0,0 +1,13 @@
+#include "Status.h"
+#include "WebPage.h"
+#include <sstream>
+
+Status::Status(WebPage *page, QObject *parent) : Command(page, parent) {
+}
+
+void Status::start(QStringList &arguments) {
+ Q_UNUSED(arguments);
+ int status = page()->getLastStatus();
+ emit finished(new Response(true, QString::number(status)));
+}
+
View
@@ -0,0 +1,12 @@
+#include "Command.h"
+
+class WebPage;
+
+class Status : public Command {
+ Q_OBJECT
+
+ public:
+ Status(WebPage *page, QObject *parent = 0);
+ virtual void start(QStringList &arguments);
+};
+
View
@@ -10,7 +10,9 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
m_loading = false;
- this->setNetworkAccessManager(new NetworkAccessManager());
+ NetworkAccessManager *manager = new NetworkAccessManager();
+ this->setNetworkAccessManager(manager);
+ connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
@@ -164,3 +166,24 @@ bool WebPage::extension(Extension extension, const ExtensionOption *option, Exte
QString WebPage::getLastAttachedFileName() {
return currentFrame()->evaluateJavaScript(QString("Capybara.lastAttachedFile")).toString();
}
+
+void WebPage::replyFinished(QNetworkReply *reply) {
+ QStringList headers;
+ lastStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ QList<QByteArray> list = reply->rawHeaderList();
+
+ int length = list.size();
+ for(int i = 0; i < length; i++) {
+ headers << list.at(i)+": "+reply->rawHeader(list.at(i));
+ }
+
+ m_pageHeaders = headers.join("\n");
+}
+
+int WebPage::getLastStatus() {
+ return lastStatus;
+}
+
+QString WebPage::pageHeaders() {
+ return m_pageHeaders;
+}
View
@@ -10,6 +10,7 @@ class WebPage : public QWebPage {
QString failureString();
QString userAgentForUrl(const QUrl &url ) const;
void setUserAgent(QString userAgent);
+ int getLastStatus();
bool render(const QString &fileName);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
@@ -19,7 +20,9 @@ class WebPage : public QWebPage {
void loadStarted();
void loadFinished(bool);
bool isLoading() const;
+ QString pageHeaders();
void frameCreated(QWebFrame *);
+ void replyFinished(QNetworkReply *reply);
protected:
virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID);
@@ -35,5 +38,7 @@ class WebPage : public QWebPage {
QString getLastAttachedFileName();
void loadJavascript();
void setUserStylesheet();
+ int lastStatus;
+ QString m_pageHeaders;
};
View
@@ -15,3 +15,5 @@ CHECK_COMMAND(FrameFocus)
CHECK_COMMAND(Header)
CHECK_COMMAND(Render)
CHECK_COMMAND(Body)
+CHECK_COMMAND(Status)
+CHECK_COMMAND(Headers)
View
@@ -1,8 +1,8 @@
TEMPLATE = app
TARGET = webkit_server
DESTDIR = .
-HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h FrameFocus.h Response.h NetworkAccessManager.h Header.h Render.h body.h
-SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp FrameFocus.cpp Response.cpp NetworkAccessManager.cpp Header.cpp Render.cpp body.cpp
+HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h FrameFocus.h Response.h NetworkAccessManager.h Header.h Render.h body.h Status.h Headers.h
+SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp FrameFocus.cpp Response.cpp NetworkAccessManager.cpp Header.cpp Render.cpp body.cpp Status.cpp Headers.cpp
RESOURCES = webkit_server.qrc
QT += network webkit
CONFIG += console

0 comments on commit 585fbbc

Please sign in to comment.