mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/arangodb/arangodb into devel
This commit is contained in:
commit
861b3024bd
|
@ -284,8 +284,7 @@ void RestSimpleHandler::removeByKeys(VPackSlice const& slice) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
|
||||
// TODO needs to generalized
|
||||
auto response = dynamic_cast<HttpResponse*>(_response.get());
|
||||
auto response = _response.get();
|
||||
|
||||
if (response == nullptr) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
|
||||
|
@ -364,7 +363,6 @@ void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
|
|||
VPackObjectBuilder guard(&result);
|
||||
resetResponse(rest::ResponseCode::OK);
|
||||
|
||||
// TODO this should be generalized
|
||||
response->setContentType(rest::ContentType::JSON);
|
||||
|
||||
if (qResult.isArray()) {
|
||||
|
|
|
@ -42,7 +42,7 @@ RestUploadHandler::RestUploadHandler(GeneralRequest* request,
|
|||
RestUploadHandler::~RestUploadHandler() {}
|
||||
|
||||
RestStatus RestUploadHandler::execute() {
|
||||
// cast is ok because http requst is required
|
||||
// cast is ok because http request is required
|
||||
HttpRequest* request = dynamic_cast<HttpRequest*>(_request.get());
|
||||
|
||||
if (request == nullptr) {
|
||||
|
@ -59,26 +59,46 @@ RestStatus RestUploadHandler::execute() {
|
|||
return RestStatus::DONE;
|
||||
}
|
||||
|
||||
char* filename = nullptr;
|
||||
std::string errorMessage;
|
||||
long systemError;
|
||||
std::string filenameString;
|
||||
{
|
||||
char* filename = nullptr;
|
||||
std::string errorMessage;
|
||||
long systemError;
|
||||
|
||||
if (TRI_GetTempName("uploads", &filename, false, systemError, errorMessage) !=
|
||||
TRI_ERROR_NO_ERROR) {
|
||||
errorMessage = "could not generate temp file: " + errorMessage;
|
||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
||||
TRI_ERROR_INTERNAL, errorMessage);
|
||||
return RestStatus::FAIL;
|
||||
if (TRI_GetTempName("uploads", &filename, false, systemError, errorMessage) !=
|
||||
TRI_ERROR_NO_ERROR) {
|
||||
errorMessage = "could not generate temp file: " + errorMessage;
|
||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
||||
TRI_ERROR_INTERNAL, errorMessage);
|
||||
return RestStatus::FAIL;
|
||||
}
|
||||
|
||||
if (filename == nullptr) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
filenameString.append(filename);
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, filename);
|
||||
}
|
||||
|
||||
char* relative = TRI_GetFilename(filename);
|
||||
std::string relativeString;
|
||||
{
|
||||
char* relative = TRI_GetFilename(filenameString.c_str());
|
||||
|
||||
if (relative == nullptr) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
relativeString.append(relative);
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, relative);
|
||||
}
|
||||
|
||||
std::string const& bodyStr = request->body();
|
||||
char const* body = bodyStr.c_str();
|
||||
size_t bodySize = bodyStr.size();
|
||||
|
||||
LOG(TRACE) << "saving uploaded file of length " << bodySize << " in file '"
|
||||
<< filename << "', relative '" << relative << "'";
|
||||
<< filenameString << "', relative '" << relativeString << "'";
|
||||
|
||||
bool found;
|
||||
std::string const& value = request->value("multipart", found);
|
||||
|
@ -88,8 +108,6 @@ RestStatus RestUploadHandler::execute() {
|
|||
|
||||
if (multiPart) {
|
||||
if (!parseMultiPart(body, bodySize)) {
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, relative);
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, filename);
|
||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
||||
TRI_ERROR_INTERNAL, "invalid multipart request");
|
||||
return RestStatus::FAIL;
|
||||
|
@ -98,18 +116,14 @@ RestStatus RestUploadHandler::execute() {
|
|||
}
|
||||
|
||||
try {
|
||||
FileUtils::spit(std::string(filename), body, bodySize);
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, filename);
|
||||
FileUtils::spit(filenameString, body, bodySize);
|
||||
} catch (...) {
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, relative);
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, filename);
|
||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
||||
TRI_ERROR_INTERNAL, "could not save file");
|
||||
return RestStatus::FAIL;
|
||||
}
|
||||
|
||||
char* fullName = TRI_Concatenate2File("uploads", relative);
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, relative);
|
||||
std::string fullName = basics::FileUtils::buildFilename("uploads", relativeString);
|
||||
|
||||
// create the response
|
||||
resetResponse(rest::ResponseCode::CREATED);
|
||||
|
@ -118,7 +132,6 @@ RestStatus RestUploadHandler::execute() {
|
|||
|
||||
b.add(VPackValue(VPackValueType::Object));
|
||||
b.add("filename", VPackValue(fullName));
|
||||
TRI_Free(TRI_CORE_MEM_ZONE, fullName);
|
||||
b.close();
|
||||
|
||||
VPackSlice s = b.slice();
|
||||
|
|
|
@ -783,7 +783,7 @@ static void ResponseV8ToCpp(v8::Isolate* isolate, TRI_v8_global_t const* v8g,
|
|||
// .........................................................................
|
||||
// cookies
|
||||
// .........................................................................
|
||||
HttpResponse* httpResponse = dynamic_cast<HttpResponse*>(response);
|
||||
|
||||
TRI_GET_GLOBAL_STRING(CookiesKey);
|
||||
if (res->Has(CookiesKey)) {
|
||||
v8::Handle<v8::Value> val = res->Get(CookiesKey);
|
||||
|
@ -791,6 +791,7 @@ static void ResponseV8ToCpp(v8::Isolate* isolate, TRI_v8_global_t const* v8g,
|
|||
|
||||
switch (response->transportType()) {
|
||||
case Endpoint::TransportType::HTTP: {
|
||||
HttpResponse* httpResponse = dynamic_cast<HttpResponse*>(response);
|
||||
if (v8Cookies->IsArray()) {
|
||||
v8::Handle<v8::Array> v8Array = v8Cookies.As<v8::Array>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue