diff --git a/include/cppmicrohttpd/request/request.h b/include/cppmicrohttpd/request/request.h index b66e16b..8b880c3 100644 --- a/include/cppmicrohttpd/request/request.h +++ b/include/cppmicrohttpd/request/request.h @@ -51,6 +51,26 @@ namespace cppmicrohttpd */ 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. * diff --git a/include/cppmicrohttpd/request/request.inl b/include/cppmicrohttpd/request/request.inl index b057dce..ea7f051 100644 --- a/include/cppmicrohttpd/request/request.inl +++ b/include/cppmicrohttpd/request/request.inl @@ -16,6 +16,20 @@ namespace cppmicrohttpd , version (p_version) { } + std::string request::get_header(const std::string& key) const + { + std::string value; + get_header(key, value); + return value; + } + + bool request::get_header(const std::string& key, std::string& value) const + { + auto v = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, key.c_str()); + if (v) value.assign(v); + return static_cast(v); + } + template void request::set_error(const T_exception& p_error) { diff --git a/test/helper/libmicrohttpd_mock.cpp b/test/helper/libmicrohttpd_mock.cpp index 87ae2c9..ca1d5ca 100644 --- a/test/helper/libmicrohttpd_mock.cpp +++ b/test/helper/libmicrohttpd_mock.cpp @@ -7,14 +7,14 @@ extern "C" int MHD_get_fdset2( struct MHD_Daemon *daemon, - ::cppcore::fdset * read_::cppcore::fdset, - ::cppcore::fdset * write_::cppcore::fdset, - ::cppcore::fdset * except_::cppcore::fdset, + fd_set * read_fdset, + fd_set * write_fdset, + fd_set * except_fdset, int * max_fd, - unsigned int ::cppcore::fdsetsize) + unsigned int fdsetsize) { return libmicrohttpd_mock::instance - ? libmicrohttpd_mock::instance->MHD_get_fdset2(daemon, read_::cppcore::fdset, write_::cppcore::fdset, except_::cppcore::fdset, max_fd, ::cppcore::fdsetsize) + ? libmicrohttpd_mock::instance->MHD_get_fdset2(daemon, read_fdset, write_fdset, except_fdset, max_fd, fdsetsize) : MHD_NO; } @@ -29,12 +29,12 @@ extern "C" int MHD_run_from_select ( struct MHD_Daemon * daemon, - const ::cppcore::fdset * read_::cppcore::fdset, - const ::cppcore::fdset * write_::cppcore::fdset, - const ::cppcore::fdset * except_::cppcore::fdset) + const fd_set * read_fdset, + const fd_set * write_fdset, + const fd_set * except_fdset) { return libmicrohttpd_mock::instance - ? libmicrohttpd_mock::instance->MHD_run_from_select(daemon, read_::cppcore::fdset, write_::cppcore::fdset, except_::cppcore::fdset) + ? libmicrohttpd_mock::instance->MHD_run_from_select(daemon, read_fdset, write_fdset, except_fdset) : MHD_NO; } diff --git a/test/helper/libmicrohttpd_mock.h b/test/helper/libmicrohttpd_mock.h index fddd0b6..4ede28c 100644 --- a/test/helper/libmicrohttpd_mock.h +++ b/test/helper/libmicrohttpd_mock.h @@ -10,11 +10,11 @@ public: MOCK_METHOD6( MHD_get_fdset2, int (struct MHD_Daemon *daemon, - ::cppcore::fdset * read_::cppcore::fdset, - ::cppcore::fdset * write_::cppcore::fdset, - ::cppcore::fdset * except_::cppcore::fdset, + fd_set * read_fdset, + fd_set * write_fdset, + fd_set * except_fdset, int * max_fd, - unsigned int ::cppcore::fdsetsize)); + unsigned int fdsetsize)); MOCK_METHOD2( MHD_get_timeout, @@ -24,9 +24,9 @@ public: MOCK_METHOD4( MHD_run_from_select, int (struct MHD_Daemon * daemon, - const ::cppcore::fdset * read_::cppcore::fdset, - const ::cppcore::fdset * write_::cppcore::fdset, - const ::cppcore::fdset * except_::cppcore::fdset)); + const fd_set * read_fdset, + const fd_set * write_fdset, + const fd_set * except_fdset)); MOCK_METHOD6( MHD_start_daemon,