QtHttpClientWrapper.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef QTHTTPCLIENTWRAPPER_H
  2. #define QTHTTPCLIENTWRAPPER_H
  3. #include <QObject>
  4. #include <QString>
  5. class QTcpSocket;
  6. class QtHttpRequest;
  7. class QtHttpReply;
  8. class QtHttpServer;
  9. class WebSocketClient;
  10. class WebJsonRpc;
  11. class QtHttpClientWrapper : public QObject {
  12. Q_OBJECT
  13. public:
  14. explicit QtHttpClientWrapper (QTcpSocket * sock, const bool& localConnection, QtHttpServer * parent);
  15. static const char SPACE = ' ';
  16. static const char COLON = ':';
  17. static const QByteArray & CRLF;
  18. enum ParsingStatus {
  19. ParsingError = -1,
  20. AwaitingRequest = 0,
  21. AwaitingHeaders = 1,
  22. AwaitingContent = 2,
  23. RequestParsed = 3
  24. };
  25. QString getGuid (void);
  26. /// @brief Wrapper for sendReplyToClient(), handles m_parsingStatus and signal connect
  27. void sendToClientWithReply (QtHttpReply * reply);
  28. ///
  29. /// @brief close a connection with FORBIDDEN header (used from JsonAPI over HTTP)
  30. ///
  31. void closeConnection();
  32. private slots:
  33. void onClientDataReceived (void);
  34. protected:
  35. ParsingStatus sendReplyToClient (QtHttpReply * reply);
  36. protected slots:
  37. void onReplySendHeadersRequested (void);
  38. void onReplySendDataRequested (void);
  39. private:
  40. QString m_guid;
  41. ParsingStatus m_parsingStatus;
  42. QTcpSocket * m_sockClient;
  43. QtHttpRequest * m_currentRequest;
  44. QtHttpServer * m_serverHandle;
  45. const bool m_localConnection;
  46. WebSocketClient * m_websocketClient;
  47. WebJsonRpc * m_webJsonRpc;
  48. };
  49. #endif // QTHTTPCLIENTWRAPPER_H