mirror of https://gitee.com/bigwinds/arangodb
convert contentTypes
This commit is contained in:
parent
3c4db6783c
commit
50fe64d6ca
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "HttpCommTask.h"
|
||||
|
||||
#include "Meta/conversion.h"
|
||||
#include "Basics/HybridLogicalClock.h"
|
||||
#include "GeneralServer/GeneralServer.h"
|
||||
#include "GeneralServer/GeneralServerFeature.h"
|
||||
|
@ -550,8 +551,11 @@ void HttpCommTask::processRequest() {
|
|||
}
|
||||
|
||||
// create a handler and execute
|
||||
executeRequest(_request,
|
||||
new HttpResponse(GeneralResponse::ResponseCode::SERVER_ERROR));
|
||||
HttpResponse* response =
|
||||
new HttpResponse(GeneralResponse::ResponseCode::SERVER_ERROR);
|
||||
response->setContentType(meta::to_enum<GeneralResponse::ContentType>(
|
||||
meta::underlying_value(_request->contentType())));
|
||||
executeRequest(_request, response);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -94,7 +94,7 @@ const optionsDocumentation = [
|
|||
' - `loopSleepWhen`: sleep every nth iteration',
|
||||
' - `loopSleepSec`: sleep seconds between iterations',
|
||||
'',
|
||||
' - `server`: server_url for external server',
|
||||
' - `server`: server_url (e.g. tcp://127.0.0.1:8529) for external server',
|
||||
' - `cluster`: if set to true the tests are run with the coordinator',
|
||||
' of a small local cluster',
|
||||
' - `clusterNodes`: number of DB-Servers to use',
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Christoph Uhde
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGODB_META_CONVERSION_H
|
||||
#define ARANGODB_META_CONVERSION_H 1
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace arangodb {
|
||||
namespace meta {
|
||||
namespace details {
|
||||
|
||||
template <typename E>
|
||||
using enable_enum_t = typename std::enable_if<
|
||||
std::is_enum<E>::value, typename std::underlying_type<E>::type>::type;
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
constexpr inline details::enable_enum_t<E> underlying_value(E e) noexcept {
|
||||
return static_cast<typename std::underlying_type<E>::type>(e);
|
||||
}
|
||||
|
||||
template <typename E, typename T>
|
||||
constexpr inline typename std::enable_if<
|
||||
std::is_enum<E>::value && std::is_integral<T>::value, E>::type
|
||||
to_enum(T value) noexcept {
|
||||
return static_cast<E>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -29,6 +29,7 @@
|
|||
#include <velocypack/Options.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
||||
#include "Meta/conversion.h"
|
||||
#include "Basics/Exceptions.h"
|
||||
#include "Basics/StringBuffer.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
|
@ -302,38 +303,42 @@ void HttpResponse::writeHeader(StringBuffer* output) {
|
|||
void HttpResponse::setPayload(GeneralRequest const* request,
|
||||
arangodb::velocypack::Slice const& slice,
|
||||
bool generateBody, VPackOptions const& options) {
|
||||
// VELOCYPACK
|
||||
if (request != nullptr && request->velocyPackResponse()) {
|
||||
setContentType(HttpResponse::ContentType::VPACK);
|
||||
size_t length = static_cast<size_t>(slice.byteSize());
|
||||
|
||||
if (generateBody) {
|
||||
_body.appendText(slice.startAs<const char>(), length);
|
||||
} else {
|
||||
headResponse(length);
|
||||
}
|
||||
if (request == nullptr) { // error
|
||||
}
|
||||
// VELOCYPACK
|
||||
_contentType = meta::to_enum<GeneralResponse::ContentType>(
|
||||
meta::underlying_value(request->contentType()));
|
||||
|
||||
// JSON
|
||||
else {
|
||||
setContentType(HttpResponse::ContentType::JSON);
|
||||
switch (_contentType) {
|
||||
case GeneralResponse::ContentType::VPACK: {
|
||||
size_t length = static_cast<size_t>(slice.byteSize());
|
||||
if (generateBody) {
|
||||
_body.appendText(slice.startAs<const char>(), length);
|
||||
} else {
|
||||
headResponse(length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
setContentType(HttpResponse::ContentType::JSON);
|
||||
|
||||
if (generateBody) {
|
||||
arangodb::basics::VelocyPackDumper dumper(&_body, &options);
|
||||
dumper.dumpValue(slice);
|
||||
} else {
|
||||
// TODO can we optimize this?
|
||||
// Just dump some where else to find real length
|
||||
StringBuffer tmp(TRI_UNKNOWN_MEM_ZONE, false);
|
||||
if (generateBody) {
|
||||
arangodb::basics::VelocyPackDumper dumper(&_body, &options);
|
||||
dumper.dumpValue(slice);
|
||||
} else {
|
||||
// TODO can we optimize this?
|
||||
// Just dump some where else to find real length
|
||||
StringBuffer tmp(TRI_UNKNOWN_MEM_ZONE, false);
|
||||
|
||||
// convert object to string
|
||||
VPackStringBufferAdapter buffer(tmp.stringBuffer());
|
||||
// convert object to string
|
||||
VPackStringBufferAdapter buffer(tmp.stringBuffer());
|
||||
|
||||
// usual dumping - but not to the response body
|
||||
VPackDumper dumper(&buffer, &options);
|
||||
dumper.dump(slice);
|
||||
// usual dumping - but not to the response body
|
||||
VPackDumper dumper(&buffer, &options);
|
||||
dumper.dump(slice);
|
||||
|
||||
headResponse(tmp.length());
|
||||
headResponse(tmp.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue