* refs #658, set user-agent "swift" to swift requests

some style changes in same step
This commit is contained in:
Klaus Basan
2016-05-24 00:39:20 +02:00
parent 954ddfb2e7
commit 5789bdd722
3 changed files with 23 additions and 13 deletions

View File

@@ -9,7 +9,7 @@
#include "blackmisc/network/networkutils.h"
#include "blackmisc/network/server.h"
#include "blackconfig/buildconfig.h"
#include <QAbstractSocket>
#include <QDateTime>
#include <QDebug>
@@ -29,6 +29,8 @@
#include <QVariant>
#include <QtDebug>
using namespace BlackConfig;
using namespace BlackMisc;
using namespace BlackMisc::Network;
namespace BlackMisc
@@ -43,16 +45,16 @@ namespace BlackMisc
for (int i = 0; i < interfaces.count(); i++)
{
QNetworkInterface iface = interfaces.at(i);
QNetworkInterface interface = interfaces.at(i);
// details of connection
if (withDebugOutput) qDebug() << "name:" << iface.name() << endl << "ip addresses:" << endl << "mac:" << iface.hardwareAddress() << endl;
if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
if (withDebugOutput) qDebug() << "name:" << interface.name() << endl << "ip addresses:" << endl << "mac:" << interface.hardwareAddress() << endl;
if (interface.flags().testFlag(QNetworkInterface::IsUp) && !interface.flags().testFlag(QNetworkInterface::IsLoopBack))
{
// this loop is important
for (int j = 0; j < iface.addressEntries().count(); j++)
for (int j = 0; j < interface.addressEntries().count(); j++)
{
if (withDebugOutput) qDebug() << iface.addressEntries().at(j).ip().toString() << " / " << iface.addressEntries().at(j).netmask().toString() << endl;
if (withDebugOutput) qDebug() << interface.addressEntries().at(j).ip().toString() << " / " << interface.addressEntries().at(j).netmask().toString() << endl;
// we have an interface that is up, and has an ip address, therefore the link is present
// we will only enable this check on first positive, all later results are incorrect
@@ -83,9 +85,6 @@ namespace BlackMisc
return ips;
}
/*
* Can connect to IP/port?
*/
bool CNetworkUtils::canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs)
{
if (!CNetworkUtils::hasConnectedInterface(false))
@@ -141,8 +140,8 @@ namespace BlackMisc
return false;
}
QString host(url.host());
QString scheme(url.scheme().toLower());
const QString host(url.host());
const QString scheme(url.scheme().toLower());
int p = url.port();
if (p < 0)
{
@@ -211,6 +210,12 @@ namespace BlackMisc
request.setSslConfiguration(conf);
}
void CNetworkUtils::setSwiftUserAgent(QNetworkRequest &request)
{
static const QString userAgent("swift/" + CVersion::version());
request.setRawHeader("User-Agent", userAgent.toLatin1());
}
QHttpPart CNetworkUtils::getMultipartWithDebugFlag()
{
QHttpPart textPartDebug;
@@ -257,6 +262,7 @@ namespace BlackMisc
break;
}
CNetworkUtils::ignoreSslVerification(request);
CNetworkUtils::setSwiftUserAgent(request);
return request;
}

View File

@@ -101,6 +101,9 @@ namespace BlackMisc
//! Ignore SSL verification such as self signed certificates
static void ignoreSslVerification(QNetworkRequest &request);
//! Set user agent for request
static void setSwiftUserAgent(QNetworkRequest &request);
//! Multipart with DEBUG FLAG for server
static QHttpPart getMultipartWithDebugFlag();
@@ -116,7 +119,7 @@ namespace BlackMisc
//! Multipart for JSON
static QHttpPart getJsonTextMultipart(const QByteArray &bytes);
//! Our tweakes network request
//! Our tweaked network request
static QNetworkRequest getNetworkRequest(const CUrl &url, RequestType type = Get);
//! Last modified from reply

View File

@@ -8,6 +8,7 @@
*/
#include "blackmisc/network/url.h"
#include "blackmisc/network/networkutils.h"
#include "blackmisc/propertyindex.h"
#include <QJsonValue>
@@ -139,7 +140,7 @@ namespace BlackMisc
QNetworkRequest CUrl::toNetworkRequest() const
{
return QNetworkRequest(this->toQUrl());
return CNetworkUtils::getNetworkRequest(*this);
}
CUrl CUrl::withAppendedPath(const QString &path) const