Commit 0133258d authored by Volker Krause's avatar Volker Krause
Browse files

Probe submit interface with a GET before submitting

This allows the usage of more standard-conforming redirection to migrate
the submission interface.
parent a4b2c983
......@@ -690,7 +690,7 @@ void Provider::submit()
path += QLatin1Char('/');
path += QStringLiteral("receiver/submit/") + d->productId;
url.setPath(path);
d->submit(url);
d->submitProbe(url);
}
void ProviderPrivate::submit(const QUrl &url)
......@@ -704,6 +704,39 @@ void ProviderPrivate::submit(const QUrl &url)
QObject::connect(reply, SIGNAL(finished()), q, SLOT(submitFinished()));
}
void ProviderPrivate::submitProbe(const QUrl &url)
{
QNetworkRequest request(url);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
request.setHeader(QNetworkRequest::UserAgentHeader, QString(QStringLiteral("KUserFeedback/") + QStringLiteral(KUSERFEEDBACK_VERSION_STRING)));
#endif
auto reply = networkAccessManager->get(request);
QObject::connect(reply, SIGNAL(finished()), q, SLOT(submitProbeFinished()));
}
void ProviderPrivate::submitProbeFinished()
{
auto reply = qobject_cast<QNetworkReply*>(q->sender());
Q_ASSERT(reply);
if (reply->error() != QNetworkReply::NoError) {
qCWarning(Log) << "failed to probe user feedback submission interface:" << reply->errorString() << reply->readAll();
return;
}
const auto redirectTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
if (redirectTarget.isValid()) {
if (++redirectCount >= 20) {
qCWarning(Log) << "Redirect loop on" << reply->url().resolved(redirectTarget).toString();
return;
}
submitProbe(reply->url().resolved(redirectTarget));
return;
}
return submit(reply->url());
}
void ProviderPrivate::writeAuditLog(const QDateTime &dt)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
......
......@@ -271,6 +271,7 @@ private:
ProviderPrivate * const d;
Q_PRIVATE_SLOT(d, void aboutToQuit())
Q_PRIVATE_SLOT(d, void submitFinished())
Q_PRIVATE_SLOT(d, void submitProbeFinished())
Q_PRIVATE_SLOT(d, void emitShowEncouragementMessage())
// for UI
Q_PRIVATE_SLOT(d, QByteArray jsonData(KUserFeedback::Provider::TelemetryMode))
......
......@@ -56,6 +56,8 @@ public:
bool isValidSource(AbstractDataSource *source) const;
QByteArray jsonData(Provider::TelemetryMode mode) const;
void scheduleNextSubmission();
void submitProbe(const QUrl &url);
void submitProbeFinished();
void submit(const QUrl &url);
void submitFinished();
......
......@@ -27,6 +27,11 @@ require_once('survey.php');
class Receiver
{
/** Dummy command for probing for redirects. */
function get_submit($productName)
{
}
/** Data submission command. */
function post_submit($productName)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment