mirror of https://gitee.com/bigwinds/arangodb
reviewed by jan
This commit is contained in:
parent
c3c403532b
commit
1d72053587
|
@ -49,7 +49,7 @@ void RestBaseHandler::handleError(Exception const& ex) {
|
|||
/// @brief checks if velocypack is expected as answer
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RestBaseHandler::returnVelocypack(){
|
||||
bool RestBaseHandler::returnVelocypack() const {
|
||||
auto accept = std::string(_request->header("accept"));
|
||||
if (std::string::npos == accept.find("application/x-velocypack")) {
|
||||
return false;
|
||||
|
@ -57,6 +57,15 @@ bool RestBaseHandler::returnVelocypack(){
|
|||
return true;
|
||||
}
|
||||
|
||||
void RestBaseHandler::writeResult(arangodb::velocypack::Slice const& slice, VPackOptions const& options){
|
||||
if(returnVelocypack()) {
|
||||
_response->setContentType("application/x-velocypack");
|
||||
_response->body().appendText(slice.startAs<const char>(),slice.byteSize());
|
||||
} else {
|
||||
_response->setContentType("application/json; charset=utf-8");
|
||||
dumpResponse(slice, &options);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates a result from VelocyPack
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -65,14 +74,7 @@ void RestBaseHandler::generateResult(GeneralResponse::ResponseCode code,
|
|||
VPackSlice const& slice) {
|
||||
|
||||
createResponse(code);
|
||||
|
||||
if(returnVelocypack()) {
|
||||
_response->setContentType("application/x-velocypack");
|
||||
_response->body().appendText(slice.startAs<const char>(),slice.byteSize());
|
||||
} else {
|
||||
_response->setContentType("application/json; charset=utf-8");
|
||||
dumpResponse(slice, &VPackOptions::Defaults);
|
||||
}
|
||||
writeResult(slice, VPackOptions::Defaults);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -83,13 +85,7 @@ void RestBaseHandler::generateResult(GeneralResponse::ResponseCode code,
|
|||
VPackSlice const& slice,
|
||||
std::shared_ptr<TransactionContext> context) {
|
||||
createResponse(code);
|
||||
if(returnVelocypack()) {
|
||||
_response->setContentType("application/x-velocypack");
|
||||
_response->body().appendText(slice.startAs<const char>(),slice.byteSize());
|
||||
} else {
|
||||
_response->setContentType("application/json; charset=utf-8");
|
||||
dumpResponse(slice, context->getVPackOptions());
|
||||
}
|
||||
writeResult(slice,*(context->getVPackOptions()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -114,7 +110,6 @@ void RestBaseHandler::generateError(GeneralResponse::ResponseCode code,
|
|||
void RestBaseHandler::generateError(GeneralResponse::ResponseCode code,
|
||||
int errorCode, std::string const& message) {
|
||||
createResponse(code);
|
||||
_response->setContentType("application/json; charset=utf-8");
|
||||
|
||||
VPackBuilder builder;
|
||||
try {
|
||||
|
@ -130,7 +125,7 @@ void RestBaseHandler::generateError(GeneralResponse::ResponseCode code,
|
|||
builder.add("errorNum", VPackValue(errorCode));
|
||||
builder.close();
|
||||
|
||||
dumpResponse(builder.slice(), &VPackOptions::Defaults);
|
||||
writeResult(builder.slice(), VPackOptions::Defaults);
|
||||
} catch (...) {
|
||||
// Building the error response failed
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class RestBaseHandler : public rest::HttpHandler {
|
|||
/// @brief checks if velocypack is expected as answer
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool returnVelocypack();
|
||||
bool returnVelocypack() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates a result from VelocyPack
|
||||
|
@ -97,6 +97,13 @@ class RestBaseHandler : public rest::HttpHandler {
|
|||
/// @brief dumps the response as JSON into the response string buffer
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief write result back to client
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void writeResult(arangodb::velocypack::Slice const& slice, VPackOptions const& options);
|
||||
|
||||
private:
|
||||
void dumpResponse(arangodb::velocypack::Slice const& slice,
|
||||
arangodb::velocypack::Options const* options);
|
||||
};
|
||||
|
|
|
@ -246,20 +246,7 @@ void RestVocbaseBaseHandler::generate20x(
|
|||
DOCUMENT_PATH + "/" + escapedHandle));
|
||||
}
|
||||
|
||||
if(returnVelocypack()) {
|
||||
_response->setContentType("application/x-velocypack");
|
||||
_response->body().appendText(slice.startAs<const char>(),slice.byteSize());
|
||||
} else {
|
||||
_response->setContentType("application/json; charset=utf-8");
|
||||
VPackStringBufferAdapter buffer(_response->body().stringBuffer());
|
||||
VPackDumper dumper(&buffer, options);
|
||||
try {
|
||||
dumper.dump(slice);
|
||||
} catch (...) {
|
||||
generateError(GeneralResponse::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL,
|
||||
"cannot generate output");
|
||||
}
|
||||
}
|
||||
writeResult(slice, *options);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue