mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-29 08:39:41 +01:00
Functional batch HTTP mixed mode multipart requests.
This commit is contained in:
parent
b25fd514d0
commit
a735c9f1e9
@ -183,8 +183,8 @@ int main(int argc, char* argv[]) {
|
||||
multi->setContentType(QHttpMultiPart::ContentType::MixedType);
|
||||
p1.setRawHeader("Content-Type", "application/http");
|
||||
p2.setRawHeader("Content-Type", "application/http");
|
||||
p1.setBody("GET /gmail/v1/users/me/messages\r\n");
|
||||
p2.setBody("GET /gmail/v1/users/me/labels\r\n");
|
||||
p1.setBody("GET /gmail/v1/users/me/messages/15f3427a9f6d2728\r\n");
|
||||
p2.setBody("GET /gmail/v1/users/me/messages/15f259a2c353589b\r\n");
|
||||
multi->append(p1);
|
||||
multi->append(p2);
|
||||
QNetworkRequest req;
|
||||
@ -210,7 +210,8 @@ int main(int argc, char* argv[]) {
|
||||
QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) {
|
||||
int a = 5;
|
||||
});
|
||||
srv->login();*/
|
||||
srv->login();
|
||||
*/
|
||||
|
||||
// Enter global event loop.
|
||||
return Application::exec();
|
||||
|
@ -10,8 +10,10 @@
|
||||
#define GMAIL_API_LABELS_LIST "https://www.googleapis.com/gmail/v1/users/me/labels"
|
||||
#define GMAIL_API_MSGS_LIST "https://www.googleapis.com/gmail/v1/users/me/messages"
|
||||
|
||||
#define GMAIL_DEFAULT_BATCH_SIZE 100
|
||||
#define GMAIL_DEFAULT_BATCH_SIZE 50
|
||||
#define GMAIL_MAX_BATCH_SIZE 999
|
||||
#define GMAIL_MIN_BATCH_SIZE 20
|
||||
|
||||
#define GMAIL_CONTENT_TYPE_HTTP "application/http"
|
||||
|
||||
#endif // GMAIL_DEFINITIONS_H
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "services/gmail/gmailfeed.h"
|
||||
#include "services/gmail/gmailserviceroot.h"
|
||||
|
||||
#include <QHttpMultiPart>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@ -329,6 +330,38 @@ void GmailNetworkFactory::onAuthFailed() {
|
||||
}
|
||||
|
||||
bool GmailNetworkFactory::obtainAndDecodeFullMessages(const QList<Message>& lite_messages) {
|
||||
QHttpMultiPart* multi = new QHttpMultiPart();
|
||||
|
||||
multi->setContentType(QHttpMultiPart::ContentType::MixedType);
|
||||
|
||||
foreach (const Message& msg, lite_messages) {
|
||||
QHttpPart part;
|
||||
|
||||
part.setRawHeader(HTTP_HEADERS_CONTENT_TYPE, GMAIL_CONTENT_TYPE_HTTP);
|
||||
QString full_msg_endpoint = QString("GET /gmail/v1/users/me/messages/%1\r\n").arg(msg.m_customId);
|
||||
|
||||
part.setBody(full_msg_endpoint.toUtf8());
|
||||
multi->append(part);
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
QNetworkRequest req;
|
||||
auto bearer = m_oauth2->bearer();
|
||||
|
||||
req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit());
|
||||
req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/batch"));
|
||||
auto* repl = SilentNetworkAccessManager::instance()->post(req, multi);
|
||||
|
||||
connect(repl, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
|
||||
auto resp = repl->readAll();
|
||||
auto aa = repl->error();
|
||||
|
||||
multi->deleteLater();
|
||||
repl->deleteLater();
|
||||
IOFactory::writeTextFile("b.html", resp);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user