本文整理汇总了C++中ApiRequest::hasRequestBody方法的典型用法代码示例。如果您正苦于以下问题:C++ ApiRequest::hasRequestBody方法的具体用法?C++ ApiRequest::hasRequestBody怎么用?C++ ApiRequest::hasRequestBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiRequest
的用法示例。
在下文中一共展示了ApiRequest::hasRequestBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
api_return ApiModule::handleRequest(ApiRequest& aRequest) {
// Find section
auto i = requestHandlers.find(aRequest.getStringParam(0));
if (i == requestHandlers.end()) {
aRequest.setResponseErrorStr("Invalid API section");
return websocketpp::http::status_code::bad_request;
}
aRequest.popParam();
const auto& sectionHandlers = i->second;
bool hasParamMatch = false; // for better error reporting
// Match parameters
auto handler = boost::find_if(sectionHandlers, [&](const RequestHandler& aHandler) {
// Regular matching
auto matchesParams = aHandler.matchParams(aRequest.getParameters());
if (!matchesParams) {
return false;
}
if (aHandler.method == aRequest.getMethod() || aHandler.isModuleHandler()) {
return true;
}
hasParamMatch = true;
return false;
});
if (handler == sectionHandlers.end()) {
if (hasParamMatch) {
aRequest.setResponseErrorStr("Method not supported for this command");
} else {
aRequest.setResponseErrorStr("Invalid parameters for this API section");
}
return websocketpp::http::status_code::bad_request;
}
// Check JSON payload
if (handler->requireJson && !aRequest.hasRequestBody()) {
aRequest.setResponseErrorStr("JSON body required");
return websocketpp::http::status_code::bad_request;
}
// Check permission
if (!session->getUser()->hasPermission(handler->access)) {
aRequest.setResponseErrorStr("Permission denied");
return websocketpp::http::status_code::forbidden;
}
// Exact params could be removed from the request...
return handler->f(aRequest);
}