Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

97 rader
3.0 KiB

  1. #pragma once
  2. #include <string>
  3. #include <memory>
  4. #include <microhttpd.h>
  5. #include "../types.h"
  6. #include "../response/response.h"
  7. namespace cppmicrohttpd
  8. {
  9. struct request;
  10. using request_ptr_u = std::unique_ptr<request>;
  11. /**
  12. * @brief Abstract request class.
  13. */
  14. struct request
  15. {
  16. private:
  17. using exception_ptr_u = std::unique_ptr<const std::exception>;
  18. public:
  19. MHD_Connection * const connection; //!< Connection this request was received at.
  20. const std::string url; //!< The URL requested by the client.
  21. const std::string method; //!< The HTTP method used by the client.
  22. const std::string version; //!< The HTTP version string.
  23. response_ptr_u response; //!< Response assigned to this request.
  24. exception_ptr_u error; //!< Error that occured during the request was handled.
  25. public:
  26. /**
  27. * @brief Constructor.
  28. *
  29. * @param[in] p_connection Connection this request was received at.
  30. * @param[in] p_url The URL requested by the client.
  31. * @param[in] p_method The HTTP method used by the client.
  32. * @param[in] p_version The HTTP version string.
  33. */
  34. inline request(
  35. MHD_Connection * const p_connection,
  36. const std::string& p_url,
  37. const std::string& p_method,
  38. const std::string& p_version);
  39. /**
  40. * @brief Destructor.
  41. */
  42. virtual ~request() = default;
  43. /**
  44. * @brief Get a value from the header.
  45. *
  46. * @param[in] key Key ot the value to look for.
  47. *
  48. * @return Header value or empty string if not found.
  49. */
  50. inline std::string get_header(const std::string& key) const;
  51. /**
  52. * @brief Get a value from the header.
  53. *
  54. * @param[in] key Key ot the value to look for.
  55. * @param[out] value Value from the header.
  56. *
  57. * @retval true If the header value was found.
  58. * @retval false If the header value was not found.
  59. */
  60. inline bool get_header(const std::string& key, std::string& value) const;
  61. /**
  62. * @brief Set HTTP error, if an error is already set, the new error is ignored.
  63. *
  64. * @param[in] p_error Http error to set.
  65. */
  66. template<typename T_exception>
  67. inline void set_error(const T_exception& p_error);
  68. /**
  69. * @brief Handle uploaded data.
  70. *
  71. * @param[in] p_data Received post data.
  72. * @param[in,out] p_size Number of bytes stored in postData.
  73. *
  74. * @retval true If the request is not yet finished.
  75. * @retval false If the request is finished.
  76. */
  77. virtual bool handle_post_pata(
  78. const void * p_data,
  79. size_t& p_size);
  80. };
  81. }