mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Ref T32, utility functions for URL/URL list
* keep error messages of failed URLs * append query
This commit is contained in:
@@ -96,17 +96,16 @@ namespace BlackMisc
|
||||
{
|
||||
const QString q(stripQueryString(queryToAppend));
|
||||
if (q.isEmpty()) { return m_query; }
|
||||
if (!hasQuery())
|
||||
{
|
||||
this->setQuery(q);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_query = m_query + "&" + q;
|
||||
}
|
||||
m_query += hasQuery() ? "&" + q : q;
|
||||
return m_query;
|
||||
}
|
||||
|
||||
QString CUrl::appendQuery(const QString &key, const QString &value)
|
||||
{
|
||||
if (key.isEmpty()) { return m_query; }
|
||||
return this->appendQuery(key + "=" + value);
|
||||
}
|
||||
|
||||
QString CUrl::getFullUrl(bool withQuery) const
|
||||
{
|
||||
if (m_host.isEmpty()) { return ""; }
|
||||
|
||||
@@ -106,6 +106,9 @@ namespace BlackMisc
|
||||
//! Append query
|
||||
QString appendQuery(const QString &queryToAppend);
|
||||
|
||||
//! Append query
|
||||
QString appendQuery(const QString &key, const QString &value);
|
||||
|
||||
//! Empty
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
@@ -147,8 +147,16 @@ namespace BlackMisc
|
||||
if (!failedUrl.isEmpty()) { this->addFailedUrl(failedUrl); }
|
||||
if (!hasMoreUrlsToTry()) { return CUrl(); }
|
||||
const CUrl url(this->obtainNextUrlWithout(random, this->m_failedUrls));
|
||||
if (CNetworkUtils::canConnect(url)) { return url; }
|
||||
if (addFailedUrl(url)) { return obtainNextWorkingUrl(); }
|
||||
QString msg;
|
||||
if (CNetworkUtils::canConnect(url, msg)) { return url; }
|
||||
if (addFailedUrl(url))
|
||||
{
|
||||
if (!msg.isEmpty())
|
||||
{
|
||||
this->m_errorMsgs.append(QString("URL: %1 error: ").arg(url.toQString(), msg));
|
||||
}
|
||||
return obtainNextWorkingUrl();
|
||||
}
|
||||
return CUrl();
|
||||
}
|
||||
|
||||
|
||||
@@ -102,13 +102,17 @@ namespace BlackMisc
|
||||
//! Next working URL, test if it can be connected
|
||||
CUrl obtainNextWorkingUrl( bool random = false, const CUrl &failedUrl = CUrl());
|
||||
|
||||
//! Get the error messages
|
||||
const QStringList &getErrorMessages() const { return m_errorMsgs; }
|
||||
|
||||
//! Reset failed URL, allows to set an optional new number of max.trials
|
||||
void reset(int maxTrials = -1);
|
||||
|
||||
private:
|
||||
int m_currentIndexDistributedLoad = -1; //!< index for random access
|
||||
int m_maxTrials = 2; //!< number of max trials
|
||||
CUrlList m_failedUrls;
|
||||
int m_maxTrials = 2; //!< number of max trials
|
||||
CUrlList m_failedUrls; //!< failed tested URLs
|
||||
QStringList m_errorMsgs; //!< error messages while testing;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
Reference in New Issue
Block a user