httpreadrequest.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright 2017 Herik Lima de Castro and Marcelo Medeiros Eler
  3. Distributed under MIT license, or public domain if desired and
  4. recognized in your jurisdiction.
  5. See file LICENSE for detail.
  6. */
  7. #ifndef HTTPREADREQUEST_H
  8. #define HTTPREADREQUEST_H
  9. #include <QFile>
  10. #include <QMap>
  11. #include <QRunnable>
  12. #include <QSslConfiguration>
  13. #include <QStringList>
  14. #include <QTcpSocket>
  15. #include "httpparser.h"
  16. #include "request.h"
  17. #include "response.h"
  18. #include "cppwebframework_global.h"
  19. #include "qmapthreadsafety.h"
  20. CWF_BEGIN_NAMESPACE
  21. class Configuration;
  22. class Controller;
  23. class Session;
  24. class Filter;
  25. /**
  26. * @brief The HttpReadRequest class is created automatically by the CppWebServer and inserted <br>
  27. * in a QThreadPool, always when the CppWebServer has a call by a client(Browser).
  28. */
  29. class CPPWEBFRAMEWORKSHARED_EXPORT HttpReadRequest : public QRunnable
  30. {
  31. qintptr socketDescriptor;
  32. QMapThreadSafety<QString, Controller *> &urlController;
  33. QMapThreadSafety<QString, Session *> &sessions;
  34. const Configuration &configuration;
  35. QSslConfiguration *ssl;
  36. Filter *filter;
  37. QTcpSocket *socket = nullptr;
  38. qint64 maxUploadFile{};
  39. bool readBody(HttpParser &parser, Request &request, Response &response);
  40. bool buildSslSocket();
  41. void buildSocket();
  42. public:
  43. /**
  44. * @brief This constructor provides the necessary information to create a HttpReadRequest
  45. * @param qintptr socketDescriptor : Used to create a socket.
  46. * @param QMapThreadSafety<QString, Controller *> &urlController : All mapped controllers
  47. * @param QMapThreadSafety<QString, Session *> &sessions : Sessions.
  48. * @param QSslConfiguration *sslConfiguration : SSL configuration.
  49. * @param Filter *filter : Filter
  50. */
  51. HttpReadRequest(qintptr socketDescriptor,
  52. QMapThreadSafety<QString, Controller *> &urlController,
  53. QMapThreadSafety<QString, Session *> &sessions,
  54. const Configuration &configuration,
  55. QSslConfiguration *ssl,
  56. Filter *filter);
  57. /**
  58. * @brief Destroys dynamically allocated resources.
  59. */
  60. ~HttpReadRequest() override;
  61. /**
  62. * @brief Starts to read the requisition.
  63. */
  64. void run() override;
  65. };
  66. CWF_END_NAMESPACE
  67. #endif // HTTPREADREQUEST_H