mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 18:55:38 +08:00
* refs #658, set user-agent "swift" to swift requests
some style changes in same step
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "blackmisc/network/networkutils.h"
|
#include "blackmisc/network/networkutils.h"
|
||||||
#include "blackmisc/network/server.h"
|
#include "blackmisc/network/server.h"
|
||||||
|
#include "blackconfig/buildconfig.h"
|
||||||
#include <QAbstractSocket>
|
#include <QAbstractSocket>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -29,6 +29,8 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
using namespace BlackConfig;
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
@@ -43,16 +45,16 @@ namespace BlackMisc
|
|||||||
|
|
||||||
for (int i = 0; i < interfaces.count(); i++)
|
for (int i = 0; i < interfaces.count(); i++)
|
||||||
{
|
{
|
||||||
QNetworkInterface iface = interfaces.at(i);
|
QNetworkInterface interface = interfaces.at(i);
|
||||||
|
|
||||||
// details of connection
|
// details of connection
|
||||||
if (withDebugOutput) qDebug() << "name:" << iface.name() << endl << "ip addresses:" << endl << "mac:" << iface.hardwareAddress() << endl;
|
if (withDebugOutput) qDebug() << "name:" << interface.name() << endl << "ip addresses:" << endl << "mac:" << interface.hardwareAddress() << endl;
|
||||||
if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
|
if (interface.flags().testFlag(QNetworkInterface::IsUp) && !interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|
||||||
{
|
{
|
||||||
// this loop is important
|
// 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 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
|
// we will only enable this check on first positive, all later results are incorrect
|
||||||
@@ -83,9 +85,6 @@ namespace BlackMisc
|
|||||||
return ips;
|
return ips;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Can connect to IP/port?
|
|
||||||
*/
|
|
||||||
bool CNetworkUtils::canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs)
|
bool CNetworkUtils::canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs)
|
||||||
{
|
{
|
||||||
if (!CNetworkUtils::hasConnectedInterface(false))
|
if (!CNetworkUtils::hasConnectedInterface(false))
|
||||||
@@ -141,8 +140,8 @@ namespace BlackMisc
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString host(url.host());
|
const QString host(url.host());
|
||||||
QString scheme(url.scheme().toLower());
|
const QString scheme(url.scheme().toLower());
|
||||||
int p = url.port();
|
int p = url.port();
|
||||||
if (p < 0)
|
if (p < 0)
|
||||||
{
|
{
|
||||||
@@ -211,6 +210,12 @@ namespace BlackMisc
|
|||||||
request.setSslConfiguration(conf);
|
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 CNetworkUtils::getMultipartWithDebugFlag()
|
||||||
{
|
{
|
||||||
QHttpPart textPartDebug;
|
QHttpPart textPartDebug;
|
||||||
@@ -257,6 +262,7 @@ namespace BlackMisc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CNetworkUtils::ignoreSslVerification(request);
|
CNetworkUtils::ignoreSslVerification(request);
|
||||||
|
CNetworkUtils::setSwiftUserAgent(request);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ namespace BlackMisc
|
|||||||
//! Ignore SSL verification such as self signed certificates
|
//! Ignore SSL verification such as self signed certificates
|
||||||
static void ignoreSslVerification(QNetworkRequest &request);
|
static void ignoreSslVerification(QNetworkRequest &request);
|
||||||
|
|
||||||
|
//! Set user agent for request
|
||||||
|
static void setSwiftUserAgent(QNetworkRequest &request);
|
||||||
|
|
||||||
//! Multipart with DEBUG FLAG for server
|
//! Multipart with DEBUG FLAG for server
|
||||||
static QHttpPart getMultipartWithDebugFlag();
|
static QHttpPart getMultipartWithDebugFlag();
|
||||||
|
|
||||||
@@ -116,7 +119,7 @@ namespace BlackMisc
|
|||||||
//! Multipart for JSON
|
//! Multipart for JSON
|
||||||
static QHttpPart getJsonTextMultipart(const QByteArray &bytes);
|
static QHttpPart getJsonTextMultipart(const QByteArray &bytes);
|
||||||
|
|
||||||
//! Our tweakes network request
|
//! Our tweaked network request
|
||||||
static QNetworkRequest getNetworkRequest(const CUrl &url, RequestType type = Get);
|
static QNetworkRequest getNetworkRequest(const CUrl &url, RequestType type = Get);
|
||||||
|
|
||||||
//! Last modified from reply
|
//! Last modified from reply
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "blackmisc/network/url.h"
|
#include "blackmisc/network/url.h"
|
||||||
|
#include "blackmisc/network/networkutils.h"
|
||||||
#include "blackmisc/propertyindex.h"
|
#include "blackmisc/propertyindex.h"
|
||||||
|
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
@@ -139,7 +140,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QNetworkRequest CUrl::toNetworkRequest() const
|
QNetworkRequest CUrl::toNetworkRequest() const
|
||||||
{
|
{
|
||||||
return QNetworkRequest(this->toQUrl());
|
return CNetworkUtils::getNetworkRequest(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUrl CUrl::withAppendedPath(const QString &path) const
|
CUrl CUrl::withAppendedPath(const QString &path) const
|
||||||
|
|||||||
Reference in New Issue
Block a user