Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Make ignoring SSL errors an option.
Browse files Browse the repository at this point in the history
webkit_server takes an --ignore-ssl-errors argument.
  • Loading branch information
rectalogic authored and halogenandtoast committed Oct 14, 2011
1 parent 9cfc6b1 commit f57b3a3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Server.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@


#include <QTcpServer> #include <QTcpServer>


Server::Server(QObject *parent) : QObject(parent) { Server::Server(QObject *parent, bool ignoreSslErrors) : QObject(parent) {
m_tcp_server = new QTcpServer(this); m_tcp_server = new QTcpServer(this);
m_page = new WebPage(this); m_page = new WebPage(this);
m_page->setIgnoreSslErrors(ignoreSslErrors);
} }


bool Server::start() { bool Server::start() {
Expand Down
2 changes: 1 addition & 1 deletion src/Server.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Server : public QObject {
Q_OBJECT Q_OBJECT


public: public:
Server(QObject *parent = 0); Server(QObject *parent, bool ignoreSslErrors);
bool start(); bool start();
quint16 server_port() const; quint16 server_port() const;


Expand Down
12 changes: 11 additions & 1 deletion src/WebPage.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -194,9 +194,19 @@ void WebPage::replyFinished(QNetworkReply *reply) {
} }


void WebPage::ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors) { void WebPage::ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors) {
reply->ignoreSslErrors(errors); if (m_ignoreSslErrors)
reply->ignoreSslErrors(errors);
} }


void WebPage::setIgnoreSslErrors(bool ignore) {
m_ignoreSslErrors = ignore;
}

bool WebPage::ignoreSslErrors() {
return m_ignoreSslErrors;
}


int WebPage::getLastStatus() { int WebPage::getLastStatus() {
return m_lastStatus; return m_lastStatus;
} }
Expand Down
3 changes: 3 additions & 0 deletions src/WebPage.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class WebPage : public QWebPage {
void setCustomNetworkAccessManager(); void setCustomNetworkAccessManager();
bool render(const QString &fileName); bool render(const QString &fileName);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0); virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
void setIgnoreSslErrors(bool ignore);
bool ignoreSslErrors();


public slots: public slots:
bool shouldInterruptJavaScript(); bool shouldInterruptJavaScript();
Expand Down Expand Up @@ -47,5 +49,6 @@ class WebPage : public QWebPage {
void setUserStylesheet(); void setUserStylesheet();
int m_lastStatus; int m_lastStatus;
QString m_pageHeaders; QString m_pageHeaders;
bool m_ignoreSslErrors;
}; };


7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ int main(int argc, char **argv) {
app.setOrganizationName("thoughtbot, inc"); app.setOrganizationName("thoughtbot, inc");
app.setOrganizationDomain("thoughtbot.com"); app.setOrganizationDomain("thoughtbot.com");


Server server; QStringList args = app.arguments();
bool ignoreSslErrors = args.contains("--ignore-ssl-errors");

Server server(0, ignoreSslErrors);


if (server.start()) { if (server.start()) {
std::cout << "Capybara-webkit server started, listening on port: " << server.server_port() << std::endl; std::cout << "Capybara-webkit server started, listening on port: " << server.server_port() << std::endl;
if (ignoreSslErrors)
std::cout << "Ignoring SSL errors" << std::endl;
return app.exec(); return app.exec();
} else { } else {
std::cerr << "Couldn't start capybara-webkit server" << std::endl; std::cerr << "Couldn't start capybara-webkit server" << std::endl;
Expand Down

0 comments on commit f57b3a3

Please sign in to comment.