1
0
Fork 0

add: VppResponse

This commit is contained in:
Jan Christoph Uhde 2016-07-25 16:06:33 +02:00
parent 0e25dca075
commit ef6643e8b4
5 changed files with 175 additions and 6 deletions

View File

@ -209,6 +209,8 @@ add_library(${LIB_ARANGO} STATIC
Rest/FakeRequest.cpp
Rest/GeneralRequest.cpp
Rest/GeneralResponse.cpp
Rest/VppRequest.cpp
Rest/VppResponse.cpp
Rest/HttpRequest.cpp
Rest/HttpResponse.cpp
Rest/InitializeRest.cpp

View File

@ -47,14 +47,14 @@ VppRequest::VppRequest(ConnectionInfo const& connectionInfo,
if (0 < length) {
_contentType = ContentType::VPACK;
_contentTypeResponse = ContentType::VPACK;
parseHeader(_header);
parseHeader();
}
}
// good
VPackSlice VppRequest::payload(VPackOptions const* options) {
VPackValidator validator;
validator.validate(_payload.data(), _payload.size());
return VPackSlice(_payload().data());
}
return VPackSlice(_payload.data());
}
void VppRequest::parseHeader() {}

View File

@ -25,9 +25,14 @@
#ifndef ARANGODB_REST_VPP_REQUEST_H
#define ARANGODB_REST_VPP_REQUEST_H 1
#include "Rest/VppRequest.h"
#include "Rest/GeneralRequest.h"
#include "Endpoint/ConnectionInfo.h"
#include <velocypack/Builder.h>
#include <velocypack/Dumper.h>
#include <velocypack/Options.h>
#include <velocypack/velocypack-aliases.h>
namespace arangodb {
class RestBatchHandler;
@ -49,7 +54,8 @@ class VppRequest : public GeneralRequest {
friend class RestBatchHandler; // TODO must be removed
private:
VppRequest(ConnectionInfo const&, char const*, size_t, bool);
VppRequest(ConnectionInfo const& connectionInfo,
VPackBuffer<uint8_t>&& header, size_t length);
public:
~VppRequest();

75
lib/Rest/VppResponse.cpp Normal file
View File

@ -0,0 +1,75 @@
////////////////////////////////////////////////////////////////////////////////
/// 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 Dr. Frank Celler
/// @author Achim Brandt
////////////////////////////////////////////////////////////////////////////////
#include "VppResponse.h"
#include <velocypack/Builder.h>
#include <velocypack/Dumper.h>
#include <velocypack/Options.h>
#include <velocypack/velocypack-aliases.h>
#include "Basics/Exceptions.h"
#include "Basics/StringBuffer.h"
#include "Basics/StringUtils.h"
#include "Basics/VPackStringBufferAdapter.h"
#include "Basics/VelocyPackDumper.h"
#include "Basics/tri-strings.h"
#include "Rest/VppRequest.h"
using namespace arangodb;
using namespace arangodb::basics;
bool VppResponse::HIDE_PRODUCT_HEADER = false;
VppResponse::VppResponse(ResponseCode code)
: GeneralResponse(code),
_connectionType(CONNECTION_KEEP_ALIVE),
_body(TRI_UNKNOWN_MEM_ZONE, false),
_contentType(ContentType::VPACK) {}
void VppResponse::reset(ResponseCode code) {
_responseCode = code;
_headers.clear();
_connectionType = CONNECTION_KEEP_ALIVE;
_contentType = ContentType::TEXT;
}
void VppResponse::setPayload(GeneralRequest const* request,
arangodb::velocypack::Slice const& slice,
bool generateBody, VPackOptions const& options) {
// VELOCYPACK
if (request != nullptr && request->velocyPackResponse()) {
setContentType(VppResponse::ContentType::VPACK);
size_t length = static_cast<size_t>(slice.byteSize());
if (generateBody) {
}
} else { // JSON
setContentType(VppResponse::ContentType::JSON);
if (generateBody) {
} else {
}
}
};
void VppResponse::writeHeader(basics::StringBuffer*) {}

86
lib/Rest/VppResponse.h Normal file
View File

@ -0,0 +1,86 @@
////////////////////////////////////////////////////////////////////////////////
/// 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 Dr. Frank Celler
/// @author Achim Brandt
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_REST_VPP_RESPONSE_H
#define ARANGODB_REST_VPP_RESPONSE_H 1
#include "Rest/GeneralResponse.h"
#include "Basics/StringBuffer.h"
namespace arangodb {
class RestBatchHandler;
namespace rest {
class VppCommTask;
class GeneralCommTask;
}
class VppResponse : public GeneralResponse {
friend class rest::GeneralCommTask;
friend class rest::VppCommTask;
friend class RestBatchHandler; // TODO must be removed
explicit VppResponse(ResponseCode code);
public:
static bool HIDE_PRODUCT_HEADER;
// required by base
void reset(ResponseCode code) override final;
void setPayload(GeneralRequest const*, arangodb::velocypack::Slice const&,
bool generateBody,
arangodb::velocypack::Options const&) override final;
void writeHeader(basics::StringBuffer*) override;
basics::StringBuffer& body() override { return _body; }
void setConnectionType(ConnectionType type) override {
_connectionType = type;
}
void setContentType(ContentType type) override { _contentType = type; }
void setContentType(std::string const& contentType) override {
_headers[arangodb::StaticStrings::ContentTypeHeader] = contentType;
_contentType = ContentType::CUSTOM;
}
void setContentType(std::string&& contentType) override {
_headers[arangodb::StaticStrings::ContentTypeHeader] =
std::move(contentType);
_contentType = ContentType::CUSTOM;
}
// end - required by base
private:
//_responseCode - from Base
//_headers - from Base
ConnectionType _connectionType;
ContentType _contentType;
basics::StringBuffer _body;
};
}
#endif