Skip to content

Commit

Permalink
core: Always send user agent header (fixes #426)
Browse files Browse the repository at this point in the history
Apparently some proxies and mobile carriers require the user agent
header to be present.
  • Loading branch information
trollixx committed Nov 19, 2015
1 parent e7a9736 commit ba2270a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ void Application::extract(const QString &filePath, const QString &destination, c

QNetworkReply *Application::download(const QUrl &url)
{
static const QString userAgent = userAgentJson();
static const QString ua = userAgent();
static const QString uaJson = userAgentJson();

QNetworkRequest request(url);
request.setHeader(QNetworkRequest::UserAgentHeader, ua);

if (url.host().endsWith(QLatin1String(".zealdocs.org", Qt::CaseInsensitive)))
request.setRawHeader("X-Zeal-User-Agent", userAgent.toUtf8());
request.setRawHeader("X-Zeal-User-Agent", uaJson.toUtf8());

return m_networkManager->get(request);
}
Expand Down Expand Up @@ -218,6 +220,10 @@ void Application::applySettings()
}
}

QString Application::userAgent()
{
return QString("Zeal/%1").arg(QCoreApplication::applicationVersion());
}

QString Application::userAgentJson() const
{
Expand Down
1 change: 1 addition & 0 deletions src/core/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private slots:
void applySettings();

private:
static inline QString userAgent();
QString userAgentJson() const;

static Application *m_instance;
Expand Down

0 comments on commit ba2270a

Please sign in to comment.