diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4c2d478927..56eef74964 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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 diff --git a/lib/Rest/VppRequest.cpp b/lib/Rest/VppRequest.cpp index 66f0a278f2..9b8526a822 100644 --- a/lib/Rest/VppRequest.cpp +++ b/lib/Rest/VppRequest.cpp @@ -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() {} diff --git a/lib/Rest/VppRequest.h b/lib/Rest/VppRequest.h index 2c84f1ccef..857e0536f1 100644 --- a/lib/Rest/VppRequest.h +++ b/lib/Rest/VppRequest.h @@ -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 +#include +#include +#include + 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&& header, size_t length); public: ~VppRequest(); diff --git a/lib/Rest/VppResponse.cpp b/lib/Rest/VppResponse.cpp new file mode 100644 index 0000000000..00969259b4 --- /dev/null +++ b/lib/Rest/VppResponse.cpp @@ -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 +#include +#include +#include + +#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(slice.byteSize()); + if (generateBody) { + } + } else { // JSON + setContentType(VppResponse::ContentType::JSON); + if (generateBody) { + } else { + } + } +}; + +void VppResponse::writeHeader(basics::StringBuffer*) {} diff --git a/lib/Rest/VppResponse.h b/lib/Rest/VppResponse.h new file mode 100644 index 0000000000..f8d27a9d3b --- /dev/null +++ b/lib/Rest/VppResponse.h @@ -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