1 /* 2 This file is part of Telegram Desktop, 3 the official desktop application for the Telegram messaging service. 4 5 For license and copyright information please follow this link: 6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 7 */ 8 #pragma once 9 10 #include "mtproto/connection_abstract.h" 11 12 #include <QtNetwork/QNetworkAccessManager> 13 #include <QtNetwork/QNetworkReply> 14 15 namespace MTP { 16 namespace details { 17 18 class HttpConnection : public AbstractConnection { 19 public: 20 HttpConnection(QThread *thread, const ProxyData &proxy); 21 22 ConnectionPointer clone(const ProxyData &proxy) override; 23 24 crl::time pingTime() const override; 25 crl::time fullConnectTimeout() const override; 26 void sendData(mtpBuffer &&buffer) override; 27 void disconnectFromServer() override; 28 void connectToServer( 29 const QString &address, 30 int port, 31 const bytes::vector &protocolSecret, 32 int16 protocolDcId, 33 bool protocolForFiles) override; 34 bool isConnected() const override; 35 bool usingHttpWait() override; 36 bool needHttpWait() override; 37 38 int32 debugState() const override; 39 40 QString transport() const override; 41 QString tag() const override; 42 43 static mtpBuffer handleResponse(QNetworkReply *reply); 44 static qint32 handleError(QNetworkReply *reply); // Returns error code. 45 46 private: 47 QUrl url() const; 48 49 void requestFinished(QNetworkReply *reply); 50 51 enum class Status { 52 Waiting = 0, 53 Ready, 54 Finished, 55 }; 56 Status _status = Status::Waiting; 57 MTPint128 _checkNonce; 58 59 QNetworkAccessManager _manager; 60 QString _address; 61 62 QSet<QNetworkReply*> _requests; 63 64 crl::time _pingTime = 0; 65 66 }; 67 68 } // namespace details 69 } // namespace MTP 70