QtHttpRequest.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef QTHTTPREQUEST_H
  2. #define QTHTTPREQUEST_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <QByteArray>
  6. #include <QHash>
  7. #include <QUrl>
  8. #include <QHostAddress>
  9. #include <QMap>
  10. class QtHttpServer;
  11. class QtHttpClientWrapper;
  12. using QtHttpPostData = QMap<QString,QByteArray>;
  13. class QtHttpRequest : public QObject
  14. {
  15. Q_OBJECT
  16. public:
  17. explicit QtHttpRequest (QtHttpClientWrapper * client, QtHttpServer * parent);
  18. struct ClientInfo
  19. {
  20. QHostAddress serverAddress;
  21. QHostAddress clientAddress;
  22. };
  23. int getRawDataSize (void) const { return m_data.size (); };
  24. QUrl getUrl (void) const { return m_url; };
  25. QString getCommand (void) const { return m_command; };
  26. QByteArray getRawData (void) const { return m_data; };
  27. QList<QByteArray> getHeadersList (void) const { return m_headersHash.keys (); };
  28. QtHttpClientWrapper * getClient (void) const { return m_clientHandle; };
  29. QtHttpPostData getPostData (void) const { return m_postData; };
  30. ClientInfo getClientInfo (void) const { return m_clientInfo; };
  31. QByteArray getHeader (const QByteArray & header) const
  32. {
  33. return m_headersHash.value (header.toLower(), QByteArray ());
  34. };
  35. public slots:
  36. void setUrl (const QUrl & url) { m_url = url; };
  37. void setCommand (const QString & command) { m_command = command; };
  38. void appendRawData (const QByteArray & data) { m_data.append (data); };
  39. void setPostData (const QtHttpPostData & data) { m_postData = data; };
  40. void setClientInfo (const QHostAddress & server, const QHostAddress & client);
  41. void addHeader (const QByteArray & header, const QByteArray & value);
  42. private:
  43. QUrl m_url;
  44. QString m_command;
  45. QByteArray m_data;
  46. QtHttpServer * m_serverHandle;
  47. QtHttpClientWrapper * m_clientHandle;
  48. QHash<QByteArray, QByteArray> m_headersHash;
  49. ClientInfo m_clientInfo;
  50. QtHttpPostData m_postData;
  51. };
  52. #endif // QTHTTPREQUEST_H