Browse Source

* Implemented method to the values from the request header

* Fixed compiler errors in the tests
master
bergmann 4 years ago
parent
commit
c7b505fc4f
4 changed files with 50 additions and 16 deletions
  1. +20
    -0
      include/cppmicrohttpd/request/request.h
  2. +14
    -0
      include/cppmicrohttpd/request/request.inl
  3. +9
    -9
      test/helper/libmicrohttpd_mock.cpp
  4. +7
    -7
      test/helper/libmicrohttpd_mock.h

+ 20
- 0
include/cppmicrohttpd/request/request.h View File

@@ -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.
*


+ 14
- 0
include/cppmicrohttpd/request/request.inl View File

@@ -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<bool>(v);
}

template<typename T_exception>
void request::set_error(const T_exception& p_error)
{


+ 9
- 9
test/helper/libmicrohttpd_mock.cpp View File

@@ -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;
}



+ 7
- 7
test/helper/libmicrohttpd_mock.h View File

@@ -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,


Loading…
Cancel
Save