1
0
Fork 0

update test

This commit is contained in:
Jan Christoph Uhde 2016-08-04 15:02:04 +02:00
parent 01c1c09d5a
commit 3c4db6783c
5 changed files with 78 additions and 31 deletions

View File

@ -47,7 +47,7 @@ function RequestSuite () {
append = append || '';
return arango.getEndpoint().replace(/^tcp:/, 'http:').replace(/^ssl:/, 'https:') + base + append;
};
var buildUrlBroken = function (append) {
return arango.getEndpoint().replace(/^tcp:/, 'http:').replace(/^ssl:/, 'https:') + '/_not-there' + append;
};
@ -57,51 +57,88 @@ function RequestSuite () {
////////////////////////////////////////////////////////////////////////////////
/// @brief test http DELETE
////////////////////////////////////////////////////////////////////////////////
versionHttp: function () {
testVersionJsonJson: function () {
var path = '/_api/version';
var headers = {
'content-type': 'application/x-velocypack',
'content-type': 'application/x-velocypack'
'content-type': 'application/json',
'accept' : 'application/json'
};
var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
//var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
var res = request.post(path, {headers : headers, timeout: 300});
expect(res).to.be.a(request.Response);
expect(res.body).to.be.a('string');
expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
var obj = JSON.parse(res.body);
expect(obj.path).to.equal(path);
var expected = { "server" : "arango" , "version" : "3.0.x-devel" };
//expect(JSON.stringify(obj)).to.equal(JSON.stringify(expected));
expect(obj).to.eql(expected);
},
versionHttpVpack: function () {
// testVersionVpackJson: function () {
// var path = '/_api/version';
// var headers = {
// 'content-type': 'application/x-velocypack',
// 'accept' : 'application/json'
// };
// var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
//
// expect(res).to.be.a(request.Response);
// expect(res.body).to.be.a('string');
// expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
// var obj = JSON.parse(res.body);
// expect(obj.path).to.equal(path);
// },
//
testVersionJsonVpack: function () {
var path = '/_api/version';
var headers = {
'content-type': 'application/x-velocypack',
'content-type': 'application/x-velocypack'
'content-type': 'application/json',
'accept' : 'application/x-velocypack'
};
var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
expect(res).to.be.a(request.Response);
expect(res.body).to.be.a('string');
expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
var obj = JSON.parse(res.body);
expect(obj.path).to.equal(path);
},
vpackEcho: function () {
var path = '/_admin/echo';
var body = "foooo"
var res = request.post(buildUrl(path),{ headers : headers, body : body, timeout: 300});
//var res = request.post(buildUrl(path,false), {headers : headers, timeout: 300});
var res = request.post(path, {headers : headers, timeout: 300});
expect(res).to.be.a(request.Response);
expect(res.body).to.be.a('string');
expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
var expected = "velocypack blablba echt scheisse" ;
require("internal").print(JSON.stringify(res.body));
require("internal").print(JSON.stringify(expected));
//var obj = JSON.parse(res.body);
expect(res.body).to.equal(body);
}
expect(res.body).to.eql(expected);
},
//
// testVersionVpackVpack: function () {
// var path = '/_api/version';
// var headers = {
// 'content-type': 'application/x-velocypack',
// 'accept' : 'application/x-velocypack'
// };
// var res = request.post(buildUrl(path), {headers : headers, timeout: 300});
//
// expect(res).to.be.a(request.Response);
// expect(res.body).to.be.a('string');
// expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
// var obj = JSON.parse(res.body);
// expect(obj.path).to.equal(path);
// },
//
// ///////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////
//
// testVpackEcho: function () {
// var path = '/_admin/echo';
// var body = "foooo"
// var res = request.post(buildUrl(path),{ headers : headers, body : body, timeout: 300});
//
// expect(res).to.be.a(request.Response);
// expect(res.body).to.be.a('string');
// expect(Number(res.headers['content-length'])).to.equal(res.rawBody.length);
// //var obj = JSON.parse(res.body);
// expect(res.body).to.equal(body);
// }

View File

@ -75,7 +75,15 @@ class GeneralRequest {
};
enum class ProtocolVersion { HTTP_1_0, HTTP_1_1, VPP_1_0, UNKNOWN };
enum class ContentType { UNSET, VPACK, JSON };
enum class ContentType {
CUSTOM, // use Content-Type from _headers
JSON, // application/json
VPACK, // application/x-velocypack
TEXT, // text/plain
HTML, // text/html
DUMP, // application/x-arango-dump
UNSET
};
public:
// translate the HTTP protocol version

View File

@ -106,7 +106,8 @@ class GeneralResponse {
VPACK, // application/x-velocypack
TEXT, // text/plain
HTML, // text/html
DUMP // application/x-arango-dump
DUMP, // application/x-arango-dump
UNSET
};
enum ConnectionType {

View File

@ -69,7 +69,7 @@ HttpRequest::HttpRequest(
_vpackBuilder(nullptr),
_headers(headers) {
_contentType = contentType;
_contentTypeResponse = ContentType::JSON;
_contentTypeResponse = contentType;
}
void HttpRequest::parseHeader(size_t length) {

View File

@ -232,6 +232,7 @@ void HttpResponse::writeHeader(StringBuffer* output) {
// add "Content-Type" header
switch (_contentType) {
case ContentType::UNSET:
case ContentType::JSON:
output->appendText(TRI_CHAR_LENGTH_PAIR(
"Content-Type: application/json; charset=utf-8\r\n"));
@ -300,7 +301,7 @@ void HttpResponse::writeHeader(StringBuffer* output) {
void HttpResponse::setPayload(GeneralRequest const* request,
arangodb::velocypack::Slice const& slice,
bool generateBody, VPackOptions const& options){
bool generateBody, VPackOptions const& options) {
// VELOCYPACK
if (request != nullptr && request->velocyPackResponse()) {
setContentType(HttpResponse::ContentType::VPACK);