From 02f1c4199fc8304aeb61b7cba25dfd38d32a03da Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Mon, 15 Aug 2016 14:06:27 +0200 Subject: [PATCH] fix: now returns object instead of string --- arangod/V8Server/v8-actions.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arangod/V8Server/v8-actions.cpp b/arangod/V8Server/v8-actions.cpp index d04e8124e1..764ee8675d 100644 --- a/arangod/V8Server/v8-actions.cpp +++ b/arangod/V8Server/v8-actions.cpp @@ -569,7 +569,7 @@ static void ResponseV8ToCpp(v8::Isolate* isolate, TRI_v8_global_t const* v8g, TRI_GET_GLOBAL_STRING(ContentTypeKey); if (res->Has(ContentTypeKey)) { contentType = TRI_ObjectToString(res->Get(ContentTypeKey)); - if (contentType != "application/json") { + if (contentType.find("application/json") == std::string::npos) { jsonContent = false; } switch (response->transportType()) { @@ -658,7 +658,9 @@ static void ResponseV8ToCpp(v8::Isolate* isolate, TRI_v8_global_t const* v8g, VPackBuilder builder; v8::Handle v8_body = res->Get(BodyKey); + //LOG(ERR) << v8_body->IsString(); std::string out; + bool done = false; // decode and set out if (transformArray->IsArray()) { @@ -683,9 +685,14 @@ static void ResponseV8ToCpp(v8::Isolate* isolate, TRI_v8_global_t const* v8g, } // out is not set - if (out.empty()) { + if (out.empty() && !done) { if (jsonContent && !V8Buffer::hasInstance(isolate, v8_body)) { - TRI_V8ToVPack(isolate, builder, v8_body, false); + if (v8_body->IsString()) { + out = TRI_ObjectToString(res->Get(BodyKey)); // should get moved + } else { + TRI_V8ToVPack(isolate, builder, v8_body, false); + done = true; + } // done } else if (V8Buffer::hasInstance( isolate, @@ -710,11 +717,14 @@ static void ResponseV8ToCpp(v8::Isolate* isolate, TRI_v8_global_t const* v8g, } catch (...) { // do nothing // json could not be converted // there was no json - change content type? + LOG_TOPIC(DEBUG, Logger::COMMUNICATION) + << "failed to parse json:\n" << out; } } if (!gotJson) { - builder.add(VPackValue(out)); // add test to the builder + builder.add(VPackValue( + out)); // add output to the builder - when not added via parser } }