QtHttpReply.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef QTHTTPREPLY_H
  2. #define QTHTTPREPLY_H
  3. #include <QObject>
  4. #include <QByteArray>
  5. #include <QHash>
  6. #include <QList>
  7. class QtHttpServer;
  8. class QtHttpReply : public QObject
  9. {
  10. Q_OBJECT
  11. Q_ENUMS (StatusCode)
  12. public:
  13. explicit QtHttpReply (QtHttpServer * parent);
  14. enum StatusCode
  15. {
  16. Ok = 200,
  17. SeeOther = 303,
  18. BadRequest = 400,
  19. Forbidden = 403,
  20. NotFound = 404,
  21. MethodNotAllowed = 405,
  22. InternalError = 500,
  23. NotImplemented = 501,
  24. BadGateway = 502,
  25. ServiceUnavailable = 503,
  26. };
  27. int getRawDataSize (void) const { return m_data.size(); };
  28. bool useChunked (void) const { return m_useChunked; };
  29. StatusCode getStatusCode (void) const { return m_statusCode; };
  30. QByteArray getRawData (void) const { return m_data; };
  31. QList<QByteArray> getHeadersList (void) const { return m_headersHash.keys (); };
  32. QByteArray getHeader (const QByteArray & header) const
  33. {
  34. return m_headersHash.value (header, QByteArray ());
  35. };
  36. static const QByteArray getStatusTextForCode (StatusCode statusCode);
  37. public slots:
  38. void setUseChunked (bool chunked = false) { m_useChunked = chunked; };
  39. void setStatusCode (StatusCode statusCode) { m_statusCode = statusCode; };
  40. void appendRawData (const QByteArray & data) { m_data.append(data); };
  41. void addHeader (const QByteArray & header, const QByteArray & value);
  42. void resetRawData (void) { m_data.clear (); };
  43. signals:
  44. void requestSendHeaders (void);
  45. void requestSendData (void);
  46. private:
  47. bool m_useChunked;
  48. StatusCode m_statusCode;
  49. QByteArray m_data;
  50. QtHttpServer * m_serverHandle;
  51. QHash<QByteArray, QByteArray> m_headersHash;
  52. };
  53. #endif // QTHTTPREPLY_H