connection_http.h 1.6 KB

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