mirror of https://gitee.com/bigwinds/arangodb
add: VppRequest
This commit is contained in:
parent
a7679fe16f
commit
0e25dca075
|
@ -34,7 +34,7 @@ using namespace arangodb::basics;
|
||||||
|
|
||||||
std::string GeneralRequest::translateVersion(ProtocolVersion version) {
|
std::string GeneralRequest::translateVersion(ProtocolVersion version) {
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case ProtocolVersion::VSTREAM_1_0:
|
case ProtocolVersion::VPP_1_0:
|
||||||
return "VPP/1.0";
|
return "VPP/1.0";
|
||||||
|
|
||||||
case ProtocolVersion::HTTP_1_1:
|
case ProtocolVersion::HTTP_1_1:
|
||||||
|
@ -44,12 +44,10 @@ std::string GeneralRequest::translateVersion(ProtocolVersion version) {
|
||||||
return "HTTP/1.0";
|
return "HTTP/1.0";
|
||||||
|
|
||||||
case ProtocolVersion::UNKNOWN:
|
case ProtocolVersion::UNKNOWN:
|
||||||
default: {
|
default: { return "HTTP/1.0"; }
|
||||||
return "HTTP/1.0";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "UNKNOWN"; // in order please MSVC
|
return "UNKNOWN"; // in order please MSVC
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GeneralRequest::translateMethod(RequestType method) {
|
std::string GeneralRequest::translateMethod(RequestType method) {
|
||||||
|
@ -89,7 +87,7 @@ std::string GeneralRequest::translateMethod(RequestType method) {
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "UNKNOWN"; // in order please MSVC
|
return "UNKNOWN"; // in order please MSVC
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneralRequest::RequestType GeneralRequest::translateMethod(
|
GeneralRequest::RequestType GeneralRequest::translateMethod(
|
||||||
|
@ -126,8 +124,8 @@ void GeneralRequest::appendMethod(RequestType method, StringBuffer* buffer) {
|
||||||
buffer->appendChar(' ');
|
buffer->appendChar(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneralRequest::RequestType GeneralRequest::findRequestType(char const* ptr,
|
GeneralRequest::RequestType GeneralRequest::findRequestType(
|
||||||
size_t const length) {
|
char const* ptr, size_t const length) {
|
||||||
switch (length) {
|
switch (length) {
|
||||||
case 3:
|
case 3:
|
||||||
if (ptr[0] == 'g' && ptr[1] == 'e' && ptr[2] == 't') {
|
if (ptr[0] == 'g' && ptr[1] == 'e' && ptr[2] == 't') {
|
||||||
|
@ -216,7 +214,8 @@ std::string const& GeneralRequest::header(std::string const& key) const {
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& GeneralRequest::header(std::string const& key, bool& found) const {
|
std::string const& GeneralRequest::header(std::string const& key,
|
||||||
|
bool& found) const {
|
||||||
auto it = _headers.find(key);
|
auto it = _headers.find(key);
|
||||||
|
|
||||||
if (it == _headers.end()) {
|
if (it == _headers.end()) {
|
||||||
|
@ -240,7 +239,8 @@ std::string const& GeneralRequest::value(std::string const& key) const {
|
||||||
return StaticStrings::Empty;
|
return StaticStrings::Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& GeneralRequest::value(std::string const& key, bool& found) const {
|
std::string const& GeneralRequest::value(std::string const& key,
|
||||||
|
bool& found) const {
|
||||||
if (!_values.empty()) {
|
if (!_values.empty()) {
|
||||||
auto it = _values.find(key);
|
auto it = _values.find(key);
|
||||||
|
|
||||||
|
@ -254,7 +254,8 @@ std::string const& GeneralRequest::value(std::string const& key, bool& found) co
|
||||||
return StaticStrings::Empty;
|
return StaticStrings::Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralRequest::setArrayValue(char* key, size_t length, char const* value) {
|
void GeneralRequest::setArrayValue(char* key, size_t length,
|
||||||
|
char const* value) {
|
||||||
_arrayValues[std::string(key, length)].emplace_back(value);
|
_arrayValues[std::string(key, length)].emplace_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ class GeneralRequest {
|
||||||
ILLEGAL // must be last
|
ILLEGAL // must be last
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ProtocolVersion { HTTP_1_0, HTTP_1_1, VSTREAM_1_0, UNKNOWN };
|
enum class ProtocolVersion { HTTP_1_0, HTTP_1_1, VPP_1_0, UNKNOWN };
|
||||||
enum class ContentType { UNSET, VPACK, JSON };
|
enum class ContentType { UNSET, VPACK, JSON };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -101,7 +101,7 @@ class GeneralRequest {
|
||||||
_isRequestContextOwner(false),
|
_isRequestContextOwner(false),
|
||||||
_type(RequestType::ILLEGAL),
|
_type(RequestType::ILLEGAL),
|
||||||
_contentType(ContentType::UNSET),
|
_contentType(ContentType::UNSET),
|
||||||
_contentTypeResponse(ContentType::UNSET){}
|
_contentTypeResponse(ContentType::UNSET) {}
|
||||||
|
|
||||||
virtual ~GeneralRequest();
|
virtual ~GeneralRequest();
|
||||||
|
|
||||||
|
@ -178,7 +178,8 @@ class GeneralRequest {
|
||||||
bool velocyPackResponse() const;
|
bool velocyPackResponse() const;
|
||||||
|
|
||||||
// should toVelocyPack be renamed to payload?
|
// should toVelocyPack be renamed to payload?
|
||||||
virtual VPackSlice payload(arangodb::velocypack::Options const* options = &VPackOptions::Defaults) = 0;
|
virtual VPackSlice payload(arangodb::velocypack::Options const*
|
||||||
|
options = &VPackOptions::Defaults) = 0;
|
||||||
|
|
||||||
std::shared_ptr<VPackBuilder> toVelocyPackBuilderPtr(
|
std::shared_ptr<VPackBuilder> toVelocyPackBuilderPtr(
|
||||||
arangodb::velocypack::Options const* options) {
|
arangodb::velocypack::Options const* options) {
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// 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
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "VppRequest.h"
|
||||||
|
|
||||||
|
#include <velocypack/Builder.h>
|
||||||
|
#include <velocypack/Options.h>
|
||||||
|
#include <velocypack/Parser.h>
|
||||||
|
#include <velocypack/Validator.h>
|
||||||
|
#include <velocypack/velocypack-aliases.h>
|
||||||
|
|
||||||
|
#include "Basics/conversions.h"
|
||||||
|
#include "Basics/StaticStrings.h"
|
||||||
|
#include "Basics/StringUtils.h"
|
||||||
|
#include "Basics/tri-strings.h"
|
||||||
|
#include "Logger/Logger.h"
|
||||||
|
|
||||||
|
using namespace arangodb;
|
||||||
|
using namespace arangodb::basics;
|
||||||
|
|
||||||
|
VppRequest::VppRequest(ConnectionInfo const& connectionInfo,
|
||||||
|
VPackBuffer<uint8_t>&& header, size_t length)
|
||||||
|
: GeneralRequest(connectionInfo),
|
||||||
|
_contentLength(0),
|
||||||
|
_header(std::move(header)),
|
||||||
|
_cookies(std::unordered_map<std::string, std::string>() /*TODO remove*/) {
|
||||||
|
if (0 < length) {
|
||||||
|
_contentType = ContentType::VPACK;
|
||||||
|
_contentTypeResponse = ContentType::VPACK;
|
||||||
|
parseHeader(_header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// good
|
||||||
|
VPackSlice VppRequest::payload(VPackOptions const* options) {
|
||||||
|
VPackValidator validator;
|
||||||
|
validator.validate(_payload.data(), _payload.size());
|
||||||
|
return VPackSlice(_payload().data());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// 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_REQUEST_H
|
||||||
|
#define ARANGODB_REST_VPP_REQUEST_H 1
|
||||||
|
|
||||||
|
#include "Rest/VppRequest.h"
|
||||||
|
#include "Endpoint/ConnectionInfo.h"
|
||||||
|
|
||||||
|
namespace arangodb {
|
||||||
|
class RestBatchHandler;
|
||||||
|
|
||||||
|
namespace rest {
|
||||||
|
class GeneralCommTask;
|
||||||
|
class VppCommTask;
|
||||||
|
// class VppsCommTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace velocypack {
|
||||||
|
class Builder;
|
||||||
|
struct Options;
|
||||||
|
}
|
||||||
|
|
||||||
|
class VppRequest : public GeneralRequest {
|
||||||
|
friend class rest::VppCommTask;
|
||||||
|
// friend class rest::VppsCommTask;
|
||||||
|
friend class rest::GeneralCommTask;
|
||||||
|
friend class RestBatchHandler; // TODO must be removed
|
||||||
|
|
||||||
|
private:
|
||||||
|
VppRequest(ConnectionInfo const&, char const*, size_t, bool);
|
||||||
|
|
||||||
|
public:
|
||||||
|
~VppRequest();
|
||||||
|
|
||||||
|
public:
|
||||||
|
VPackSlice payload(arangodb::velocypack::Options const*) override;
|
||||||
|
int64_t contentLength() const override { return _contentLength; }
|
||||||
|
|
||||||
|
// TODO REMOVE
|
||||||
|
std::unordered_map<std::string, std::string> cookieValues() const override {
|
||||||
|
return _cookies;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPayload(VPackBuffer<uint8_t>&& payload) { _payload = payload; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void parseHeader(); // converts _header(vpack) to
|
||||||
|
// _headers(map<string,string>)
|
||||||
|
|
||||||
|
int64_t _contentLength;
|
||||||
|
VPackBuffer<uint8_t> _header;
|
||||||
|
VPackBuffer<uint8_t> _payload;
|
||||||
|
const std::unordered_map<std::string, std::string> _cookies; // TODO remove
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Reference in New Issue