mirror of https://gitee.com/bigwinds/arangodb
add: VPackValidator to RestVocbaseBaseHandler
This commit is contained in:
parent
e6667bf672
commit
ed789ce397
|
@ -40,6 +40,7 @@
|
||||||
#include <velocypack/Exception.h>
|
#include <velocypack/Exception.h>
|
||||||
#include <velocypack/Parser.h>
|
#include <velocypack/Parser.h>
|
||||||
#include <velocypack/Slice.h>
|
#include <velocypack/Slice.h>
|
||||||
|
#include <velocypack/Validator.h>
|
||||||
#include <velocypack/velocypack-aliases.h>
|
#include <velocypack/velocypack-aliases.h>
|
||||||
|
|
||||||
using namespace arangodb;
|
using namespace arangodb;
|
||||||
|
@ -210,7 +211,7 @@ void RestVocbaseBaseHandler::generate20x(
|
||||||
VPackSlice slice = result.slice();
|
VPackSlice slice = result.slice();
|
||||||
if (slice.isNone()) {
|
if (slice.isNone()) {
|
||||||
// will happen if silent == true
|
// will happen if silent == true
|
||||||
slice = VelocyPackHelper::EmptyObjectValue();
|
slice = VelocyPackHelper::EmptyObjectValue();
|
||||||
} else {
|
} else {
|
||||||
TRI_ASSERT(slice.isObject() || slice.isArray());
|
TRI_ASSERT(slice.isObject() || slice.isArray());
|
||||||
if (slice.isObject()) {
|
if (slice.isObject()) {
|
||||||
|
@ -645,14 +646,16 @@ std::shared_ptr<VPackBuilder> RestVocbaseBaseHandler::parseVelocyPackBody(
|
||||||
try {
|
try {
|
||||||
success = true;
|
success = true;
|
||||||
|
|
||||||
#if 0
|
|
||||||
// currently deactivated...
|
|
||||||
bool found;
|
bool found;
|
||||||
std::string const& contentType =
|
std::string const& contentType =
|
||||||
_request->header(StaticStrings::ContentTypeHeader, found);
|
_request->header(StaticStrings::ContentTypeHeader, found);
|
||||||
|
|
||||||
if (found && contentType.size() == StaticStrings::MimeTypeVPack.size() &&
|
if (found && contentType.size() == StaticStrings::MimeTypeVPack.size() &&
|
||||||
contentType == StaticStrings::MimeTypeVPack) {
|
contentType == StaticStrings::MimeTypeVPack) {
|
||||||
|
|
||||||
|
VPackValidator validator;
|
||||||
|
validator.validate(_request->body().c_str(),_request->body().length());
|
||||||
|
|
||||||
VPackSlice slice{_request->body().c_str()};
|
VPackSlice slice{_request->body().c_str()};
|
||||||
auto builder = std::make_shared<VPackBuilder>(options);
|
auto builder = std::make_shared<VPackBuilder>(options);
|
||||||
builder->add(slice);
|
builder->add(slice);
|
||||||
|
@ -660,13 +663,11 @@ std::shared_ptr<VPackBuilder> RestVocbaseBaseHandler::parseVelocyPackBody(
|
||||||
} else {
|
} else {
|
||||||
return _request->toVelocyPack(options);
|
return _request->toVelocyPack(options);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
return _request->toVelocyPack(options);
|
|
||||||
#endif
|
|
||||||
} catch (std::bad_alloc const&) {
|
} catch (std::bad_alloc const&) {
|
||||||
generateOOMError();
|
generateOOMError();
|
||||||
} catch (VPackException const& e) {
|
} catch (VPackException const& e) {
|
||||||
std::string errmsg("Parse error: ");
|
std::string errmsg("VpackError error: ");
|
||||||
errmsg.append(e.what());
|
errmsg.append(e.what());
|
||||||
generateError(GeneralResponse::ResponseCode::BAD,
|
generateError(GeneralResponse::ResponseCode::BAD,
|
||||||
TRI_ERROR_HTTP_CORRUPTED_JSON, errmsg);
|
TRI_ERROR_HTTP_CORRUPTED_JSON, errmsg);
|
||||||
|
|
Loading…
Reference in New Issue