|
- #pragma once
-
- #include <string>
- #include <memory>
- #include <microhttpd.h>
-
- #include "../types.h"
- #include "../response/response.h"
-
- namespace cppmicrohttpd
- {
-
- struct request;
-
- using request_ptr_u = std::unique_ptr<request>;
-
- /**
- * @brief Abstract request class.
- */
- struct request
- {
- private:
- using exception_ptr_u = std::unique_ptr<const std::exception>;
-
- public:
- MHD_Connection * const connection; //!< Connection this request was received at.
- const std::string url; //!< The URL requested by the client.
- const std::string method; //!< The HTTP method used by the client.
- const std::string version; //!< The HTTP version string.
-
- response_ptr_u response; //!< Response assigned to this request.
- exception_ptr_u error; //!< Error that occured during the request was handled.
-
- public:
- /**
- * @brief Constructor.
- *
- * @param[in] p_connection Connection this request was received at.
- * @param[in] p_url The URL requested by the client.
- * @param[in] p_method The HTTP method used by the client.
- * @param[in] p_version The HTTP version string.
- */
- inline request(
- MHD_Connection * const p_connection,
- const std::string& p_url,
- const std::string& p_method,
- const std::string& p_version);
-
- /**
- * @brief Destructor.
- */
- virtual ~request() = default;
-
- /**
- * @brief Get a value from the header.
- *
- * @param[in] key Key ot the value to look for.
- *
- * @return Header value or empty string if not found.
- */
- inline std::string get_header(const std::string& key) const;
-
- /**
- * @brief Get a value from the header.
- *
- * @param[in] key Key ot the value to look for.
- * @param[out] value Value from the header.
- *
- * @retval true If the header value was found.
- * @retval false If the header value was not found.
- */
- inline bool get_header(const std::string& key, std::string& value) const;
-
- /**
- * @brief Set HTTP error, if an error is already set, the new error is ignored.
- *
- * @param[in] p_error Http error to set.
- */
- template<typename T_exception>
- inline void set_error(const T_exception& p_error);
-
- /**
- * @brief Handle uploaded data.
- *
- * @param[in] p_data Received post data.
- * @param[in,out] p_size Number of bytes stored in postData.
- *
- * @retval true If the request is not yet finished.
- * @retval false If the request is finished.
- */
- virtual bool handle_post_pata(
- const void * p_data,
- size_t& p_size);
- };
-
- }
|