MXS-1220: Move request body checks to a higher level

The checks whether a request body is present are now done at a higher
level. This removes the need to do the checks at the resource handler
callback, removing duplicated code.

The checks are done by adding constraints to resources that must be
fulfilled by each request.

Added debug assertions to make sure that the core logic of the REST API
resource system works.
This commit is contained in:
Markus Mäkelä
2017-08-04 21:37:19 +03:00
parent 1b65bd2a9d
commit 7e18e49eec
2 changed files with 106 additions and 97 deletions

View File

@ -37,6 +37,12 @@ class Resource
Resource& operator = (const Resource&);
public:
enum resource_constraint
{
NONE = 0,
REQUIRE_BODY = (1 << 0)
};
Resource(ResourceCallback cb, int components, ...);
~Resource();
@ -58,13 +64,28 @@ public:
*/
HttpResponse call(const HttpRequest& request) const;
/**
* Add a resource constraint
*
* @param type Constraint to add
*/
void add_constraint(resource_constraint type);
/**
* Whether resource requires a request body
*
* @return True if resource requires a request body
*/
bool requires_body() const;
private:
bool matching_variable_path(const std::string& path, const std::string& target) const;
ResourceCallback m_cb; /**< Resource handler callback */
std::deque<std::string> m_path; /**< Path components */
bool m_is_glob; /**< Does this path glob? */
ResourceCallback m_cb; /**< Resource handler callback */
std::deque<std::string> m_path; /**< Path components */
bool m_is_glob; /**< Does this path glob? */
uint32_t m_constraints; /**< Resource constraints */
};
/**