Skip to content

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
Expand Up @@ -4,9 +4,10 @@

#include <QTcpServer>

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

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

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

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

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() {
return m_lastStatus;
}
Expand Down
3 changes: 3 additions & 0 deletions src/WebPage.h
Expand Up @@ -15,6 +15,8 @@ class WebPage : public QWebPage {
void setCustomNetworkAccessManager();
bool render(const QString &fileName);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
void setIgnoreSslErrors(bool ignore);
bool ignoreSslErrors();

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

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

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

Server server(0, ignoreSslErrors);

if (server.start()) {
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();
} else {
std::cerr << "Couldn't start capybara-webkit server" << std::endl;
Expand Down

0 comments on commit f57b3a3

Please sign in to comment.