aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cpaster
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2020-07-22 17:28:02 +0200
committerChristian Stenger <christian.stenger@qt.io>2020-07-23 08:40:05 +0000
commitf1c0393d52634d6073b0d3caf20028c834de8617 (patch)
tree123ae6918e9612a3c9ba0dac28facdae18aff03b /src/plugins/cpaster
parentdef7615c814ab96f7573a1478117d0f0c7909305 (diff)
CPaster: Fix fetching from DPaste
Currently the fetch location has moved. Change-Id: Ie4cd3bf4b1050ca2c0cc17bde553f546232882e7 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cpaster')
-rw-r--r--src/plugins/cpaster/dpastedotcomprotocol.cpp39
-rw-r--r--src/plugins/cpaster/dpastedotcomprotocol.h1
2 files changed, 29 insertions, 11 deletions
diff --git a/src/plugins/cpaster/dpastedotcomprotocol.cpp b/src/plugins/cpaster/dpastedotcomprotocol.cpp
index 1a0d9c6194..aac2398498 100644
--- a/src/plugins/cpaster/dpastedotcomprotocol.cpp
+++ b/src/plugins/cpaster/dpastedotcomprotocol.cpp
@@ -46,20 +46,37 @@ void DPasteDotComProtocol::fetch(const QString &id)
{
QNetworkReply * const reply = httpGet(baseUrl() + '/' + id + ".txt");
connect(reply, &QNetworkReply::finished, this, [this, id, reply] {
- QString title;
- QString content;
- const bool error = reply->error();
- if (error) {
- content = reply->errorString();
- } else {
- title = name() + ": " + id;
- content = QString::fromUtf8(reply->readAll());
- }
- reply->deleteLater();
- emit fetchDone(title, content, error);
+ fetchFinished(id, reply, false);
});
}
+void DPasteDotComProtocol::fetchFinished(const QString &id, QNetworkReply * const reply,
+ bool alreadyRedirected)
+{
+ const int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ if (status >= 300 && status <= 308 && status != 306) {
+ if (!alreadyRedirected) {
+ QNetworkReply * const newRep = httpGet(QString::fromUtf8(reply->rawHeader("Location")));
+ connect(newRep, &QNetworkReply::finished, this, [this, id, newRep] {
+ fetchFinished(id, newRep, true);
+ });
+ reply->deleteLater();
+ return;
+ }
+ }
+ QString title;
+ QString content;
+ const bool error = reply->error();
+ if (error) {
+ content = reply->errorString();
+ } else {
+ title = name() + ": " + id;
+ content = QString::fromUtf8(reply->readAll());
+ }
+ reply->deleteLater();
+ emit fetchDone(title, content, error);
+}
+
static QByteArray typeToString(Protocol::ContentType type)
{
switch (type) {
diff --git a/src/plugins/cpaster/dpastedotcomprotocol.h b/src/plugins/cpaster/dpastedotcomprotocol.h
index 6f01649578..9b39052d8c 100644
--- a/src/plugins/cpaster/dpastedotcomprotocol.h
+++ b/src/plugins/cpaster/dpastedotcomprotocol.h
@@ -40,6 +40,7 @@ private:
bool hasSettings() const override { return false; }
unsigned capabilities() const override;
void fetch(const QString &id) override;
+ void fetchFinished(const QString &id, QNetworkReply * const reply, bool alreadyRedirected);
void paste(const QString &text,
ContentType ct = Text,
int expiryDays = 1,