1
0
Fork 0

fix: createResponse -> setResponseCode; remove delete

remove delete _response in RestEdgesHandler
This commit is contained in:
Jan Christoph Uhde 2016-07-07 08:54:41 +00:00
parent d5a64253ec
commit b2e29c4353
22 changed files with 58 additions and 57 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
tags
build
core.*
.deps
.dirstamp

View File

@ -76,7 +76,7 @@ void RestAgencyHandler::redirectRequest(arangodb::consensus::id_t leaderId) {
std::string url =
Endpoint::uriForm(_agent->config().endpoints.at(leaderId)) +
_request->requestPath();
createResponse(GeneralResponse::ResponseCode::TEMPORARY_REDIRECT);
setResponseCode(GeneralResponse::ResponseCode::TEMPORARY_REDIRECT);
_response->setHeaderNC(StaticStrings::Location, url);
} catch (std::exception const& e) {
LOG_TOPIC(WARN, Logger::AGENCY) << e.what() << " " << __FILE__ << __LINE__;

View File

@ -919,6 +919,6 @@ std::shared_ptr<VPackBuilder> RestAqlHandler::parseVelocyPackBody() {
void RestAqlHandler::sendResponse(
GeneralResponse::ResponseCode code, VPackSlice const slice,
arangodb::TransactionContext* transactionContext) {
createResponse(code);
setResponseCode(code);
writeResult(slice, *(transactionContext->getVPackOptionsForDump()));
}

View File

@ -74,10 +74,10 @@ RestHandler::status RestAgencyCallbacksHandler::execute() {
auto callback = _agencyCallbackRegistry->getCallback(index);
LOG(DEBUG) << "Agency callback has been triggered. refetching!";
callback->refetchAndUpdate(true);
createResponse(arangodb::GeneralResponse::ResponseCode::ACCEPTED);
setResponseCode(arangodb::GeneralResponse::ResponseCode::ACCEPTED);
} catch (arangodb::basics::Exception const&) {
// mop: not found...expected
createResponse(arangodb::GeneralResponse::ResponseCode::NOT_FOUND);
setResponseCode(arangodb::GeneralResponse::ResponseCode::NOT_FOUND);
}
return status::DONE;
}

View File

@ -55,7 +55,7 @@ RestHandler::status RestShardHandler::execute() {
ClusterComm::instance()->processAnswer(coordinatorHeader, stealRequest());
if (result == "") {
createResponse(arangodb::GeneralResponse::ResponseCode::ACCEPTED);
setResponseCode(arangodb::GeneralResponse::ResponseCode::ACCEPTED);
} else {
generateError(arangodb::GeneralResponse::ResponseCode::BAD,
(int)arangodb::GeneralResponse::ResponseCode::BAD,

View File

@ -85,7 +85,7 @@ RestHandler::status PathHandler::execute() {
}
url += defaultFile;
createResponse(GeneralResponse::ResponseCode::MOVED_PERMANENTLY);
setResponseCode(GeneralResponse::ResponseCode::MOVED_PERMANENTLY);
response->setHeaderNC(StaticStrings::Location, url);
response->setContentType(HttpResponse::ContentType::HTML);
@ -108,7 +108,7 @@ RestHandler::status PathHandler::execute() {
if (next == ".") {
LOG(WARN) << "file '" << name << "' contains '.'";
createResponse(GeneralResponse::ResponseCode::FORBIDDEN);
setResponseCode(GeneralResponse::ResponseCode::FORBIDDEN);
response->body().appendText("path contains '.'");
return status::DONE;
}
@ -116,7 +116,7 @@ RestHandler::status PathHandler::execute() {
if (next == "..") {
LOG(WARN) << "file '" << name << "' contains '..'";
createResponse(GeneralResponse::ResponseCode::FORBIDDEN);
setResponseCode(GeneralResponse::ResponseCode::FORBIDDEN);
response->body().appendText("path contains '..'");
return status::DONE;
}
@ -126,7 +126,7 @@ RestHandler::status PathHandler::execute() {
if (sc != std::string::npos) {
LOG(WARN) << "file '" << name << "' contains illegal character";
createResponse(GeneralResponse::ResponseCode::FORBIDDEN);
setResponseCode(GeneralResponse::ResponseCode::FORBIDDEN);
response->body().appendText("path contains illegal character '" +
std::string(1, next[sc]) + "'");
return status::DONE;
@ -136,7 +136,7 @@ RestHandler::status PathHandler::execute() {
if (!FileUtils::isDirectory(path)) {
LOG(WARN) << "file '" << name << "' not found";
createResponse(GeneralResponse::ResponseCode::NOT_FOUND);
setResponseCode(GeneralResponse::ResponseCode::NOT_FOUND);
response->body().appendText("file not found");
return status::DONE;
}
@ -148,7 +148,7 @@ RestHandler::status PathHandler::execute() {
if (!allowSymbolicLink && FileUtils::isSymbolicLink(name)) {
LOG(WARN) << "file '" << name << "' contains symbolic link";
createResponse(GeneralResponse::ResponseCode::FORBIDDEN);
setResponseCode(GeneralResponse::ResponseCode::FORBIDDEN);
response->body().appendText("symbolic links are not allowed");
return status::DONE;
}
@ -157,19 +157,19 @@ RestHandler::status PathHandler::execute() {
if (!FileUtils::isRegularFile(name)) {
LOG(WARN) << "file '" << name << "' not found";
createResponse(GeneralResponse::ResponseCode::NOT_FOUND);
setResponseCode(GeneralResponse::ResponseCode::NOT_FOUND);
response->body().appendText("file not found");
return status::DONE;
}
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
try {
FileUtils::slurp(name, response->body());
} catch (...) {
LOG(WARN) << "file '" << name << "' not readable";
createResponse(GeneralResponse::ResponseCode::NOT_FOUND);
setResponseCode(GeneralResponse::ResponseCode::NOT_FOUND);
response->body().appendText("file not readable");
return status::DONE;
}
@ -208,7 +208,7 @@ RestHandler::status PathHandler::execute() {
}
void PathHandler::handleError(Exception const&) {
createResponse(GeneralResponse::ResponseCode::SERVER_ERROR);
setResponseCode(GeneralResponse::ResponseCode::SERVER_ERROR);
}
}
}

View File

@ -127,6 +127,7 @@ GeneralResponse* RestHandler::stealResponse() {
return tmp;
}
void RestHandler::createResponse(GeneralResponse::ResponseCode code) {
void RestHandler::setResponseCode(GeneralResponse::ResponseCode code) {
TRI_ASSERT(_response != nullptr);
_response->reset(code);
}

View File

@ -116,8 +116,8 @@ class RestHandler : public RequestStatisticsAgent, public arangodb::WorkItem {
GeneralResponse* stealResponse();
protected:
// create a new REST response
void createResponse(GeneralResponse::ResponseCode);
// sets response Code
void setResponseCode(GeneralResponse::ResponseCode);
protected:
// handler id
@ -132,6 +132,7 @@ class RestHandler : public RequestStatisticsAgent, public arangodb::WorkItem {
// the request
GeneralRequest* _request;
//OBI-TODO make private
// the response
GeneralResponse* _response;
};

View File

@ -46,13 +46,13 @@ class MaintenanceHandler : public RestHandler {
bool isDirect() const override { return true; };
status execute() override {
createResponse(GeneralResponse::ResponseCode::SERVICE_UNAVAILABLE);
setResponseCode(GeneralResponse::ResponseCode::SERVICE_UNAVAILABLE);
return status::DONE;
};
void handleError(const Exception& error) override {
createResponse(GeneralResponse::ResponseCode::SERVICE_UNAVAILABLE);
setResponseCode(GeneralResponse::ResponseCode::SERVICE_UNAVAILABLE);
};
};
}

View File

@ -52,7 +52,7 @@ void RestBaseHandler::handleError(Exception const& ex) {
void RestBaseHandler::generateResult(GeneralResponse::ResponseCode code,
VPackSlice const& slice) {
createResponse(code);
setResponseCode(code);
VPackOptions options(VPackOptions::Defaults);
options.escapeUnicode = true;
writeResult(slice, options);
@ -65,7 +65,7 @@ void RestBaseHandler::generateResult(GeneralResponse::ResponseCode code,
void RestBaseHandler::generateResult(
GeneralResponse::ResponseCode code, VPackSlice const& slice,
std::shared_ptr<TransactionContext> context) {
createResponse(code);
setResponseCode(code);
writeResult(slice, *(context->getVPackOptionsForDump()));
}
@ -90,7 +90,7 @@ void RestBaseHandler::generateError(GeneralResponse::ResponseCode code,
void RestBaseHandler::generateError(GeneralResponse::ResponseCode code,
int errorCode, std::string const& message) {
createResponse(code);
setResponseCode(code);
VPackBuilder builder;
try {

View File

@ -89,7 +89,7 @@ RestHandler::status RestBatchHandler::execute() {
httpRequest->header(StaticStrings::Authorization);
// create the response
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
response->setContentType(
httpRequest->header(StaticStrings::ContentTypeHeader));

View File

@ -136,7 +136,7 @@ void RestCursorHandler::processQuery(VPackSlice const& slice) {
TRI_ASSERT(qResult.isArray());
{
createResponse(GeneralResponse::ResponseCode::CREATED);
setResponseCode(GeneralResponse::ResponseCode::CREATED);
// TODO needs to generalized
auto* response = dynamic_cast<HttpResponse*>(_response);
@ -477,7 +477,7 @@ void RestCursorHandler::modifyCursor() {
}
try {
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
// TODO needs to generalized
auto* response = dynamic_cast<HttpResponse*>(_response);

View File

@ -499,8 +499,6 @@ bool RestEdgesHandler::readFilteredEdges() {
if (!parseSuccess) {
// We continue unfiltered
// Filter could be done by caller
delete _response;
_response = nullptr;
return readEdges(expressions);
}
VPackSlice body = parsedBody->slice();

View File

@ -262,7 +262,7 @@ void RestExportHandler::createCursor() {
bool count = arangodb::basics::VelocyPackHelper::getBooleanValue(
options, "count", false);
createResponse(GeneralResponse::ResponseCode::CREATED);
setResponseCode(GeneralResponse::ResponseCode::CREATED);
// TODO needs to generalized
auto* response = dynamic_cast<HttpResponse*>(_response);
@ -339,7 +339,7 @@ void RestExportHandler::modifyCursor() {
}
try {
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
// TODO this needs to be generalized
auto* response = dynamic_cast<HttpResponse*>(_response);

View File

@ -837,7 +837,7 @@ int RestImportHandler::performImport(SingleCollectionTransaction& trx,
void RestImportHandler::generateDocumentsCreated(
RestImportResult const& result) {
createResponse(GeneralResponse::ResponseCode::CREATED);
setResponseCode(GeneralResponse::ResponseCode::CREATED);
try {
VPackBuilder json;

View File

@ -94,7 +94,7 @@ void RestJobHandler::putJob() {
if (status == AsyncJobResult::JOB_PENDING) {
// job is still pending
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
return;
}
@ -199,11 +199,11 @@ void RestJobHandler::getJobById(std::string const& value) {
if (status == AsyncJobResult::JOB_PENDING) {
// job is still pending
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
return;
}
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -43,7 +43,7 @@ RestHandler::status RestPleaseUpgradeHandler::execute() {
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
}
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
response->setContentType(GeneralResponse::ContentType::TEXT);
auto& buffer = response->body();

View File

@ -612,7 +612,7 @@ void RestReplicationHandler::handleCommandBatch() {
int res = TRI_TouchBlockerCompactorVocBase(_vocbase, id, expires);
if (res == TRI_ERROR_NO_ERROR) {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
} else {
generateError(GeneralResponse::responseCode(res), res);
}
@ -627,7 +627,7 @@ void RestReplicationHandler::handleCommandBatch() {
int res = TRI_RemoveBlockerCompactorVocBase(_vocbase, id);
if (res == TRI_ERROR_NO_ERROR) {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
} else {
generateError(GeneralResponse::responseCode(res), res);
}
@ -728,7 +728,7 @@ void RestReplicationHandler::handleCommandBarrier() {
if (arangodb::wal::LogfileManager::instance()->extendLogfileBarrier(
id, ttl, minTick)) {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
} else {
int res = TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND;
generateError(GeneralResponse::responseCode(res), res);
@ -741,7 +741,7 @@ void RestReplicationHandler::handleCommandBarrier() {
TRI_voc_tick_t id = StringUtils::uint64(suffix[1]);
if (arangodb::wal::LogfileManager::instance()->removeLogfileBarrier(id)) {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
} else {
int res = TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND;
generateError(GeneralResponse::responseCode(res), res);
@ -845,7 +845,7 @@ void RestReplicationHandler::handleTrampolineCoordinator() {
}
bool dummy;
createResponse(static_cast<GeneralResponse::ResponseCode>(
setResponseCode(static_cast<GeneralResponse::ResponseCode>(
res->result->getHttpReturnCode()));
// TODO needs to generalized
@ -998,9 +998,9 @@ void RestReplicationHandler::handleCommandLoggerFollow() {
size_t const length = TRI_LengthStringBuffer(dump._buffer);
if (length == 0) {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
} else {
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
}
// TODO needs to generalized
@ -1101,9 +1101,9 @@ void RestReplicationHandler::handleCommandDetermineOpenTransactions() {
size_t const length = TRI_LengthStringBuffer(dump._buffer);
if (length == 0) {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
} else {
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
}
// TODO needs to generalized
@ -3057,9 +3057,9 @@ void RestReplicationHandler::handleCommandDump() {
size_t const length = TRI_LengthStringBuffer(dump._buffer);
if (length == 0) {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
} else {
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
}
// TODO needs to generalized

View File

@ -358,7 +358,7 @@ void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
VPackBuilder result;
{
VPackObjectBuilder guard(&result);
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
// TODO this should be generalized
response->setContentType(HttpResponse::ContentType::JSON);

View File

@ -112,7 +112,7 @@ RestHandler::status RestUploadHandler::execute() {
TRI_Free(TRI_CORE_MEM_ZONE, relative);
// create the response
createResponse(GeneralResponse::ResponseCode::CREATED);
setResponseCode(GeneralResponse::ResponseCode::CREATED);
VPackBuilder b;

View File

@ -168,9 +168,9 @@ void RestVocbaseBaseHandler::generateSaved(
arangodb::OperationResult const& result, std::string const& collectionName,
TRI_col_type_e type, VPackOptions const* options, bool isMultiple) {
if (result.wasSynchronous) {
createResponse(GeneralResponse::ResponseCode::CREATED);
setResponseCode(GeneralResponse::ResponseCode::CREATED);
} else {
createResponse(GeneralResponse::ResponseCode::ACCEPTED);
setResponseCode(GeneralResponse::ResponseCode::ACCEPTED);
}
if (isMultiple && !result.countErrorCodes.empty()) {
@ -195,9 +195,9 @@ void RestVocbaseBaseHandler::generateDeleted(
arangodb::OperationResult const& result, std::string const& collectionName,
TRI_col_type_e type, VPackOptions const* options) {
if (result.wasSynchronous) {
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
} else {
createResponse(GeneralResponse::ResponseCode::ACCEPTED);
setResponseCode(GeneralResponse::ResponseCode::ACCEPTED);
}
generate20x(result, collectionName, type, options);
}
@ -256,7 +256,7 @@ void RestVocbaseBaseHandler::generateForbidden() {
void RestVocbaseBaseHandler::generatePreconditionFailed(
VPackSlice const& slice) {
createResponse(GeneralResponse::ResponseCode::PRECONDITION_FAILED);
setResponseCode(GeneralResponse::ResponseCode::PRECONDITION_FAILED);
if (slice.isObject()) { // single document case
std::string const rev =
@ -310,7 +310,7 @@ void RestVocbaseBaseHandler::generatePreconditionFailed(
////////////////////////////////////////////////////////////////////////////////
void RestVocbaseBaseHandler::generateNotModified(TRI_voc_rid_t rid) {
createResponse(GeneralResponse::ResponseCode::NOT_MODIFIED);
setResponseCode(GeneralResponse::ResponseCode::NOT_MODIFIED);
_response->setHeaderNC(StaticStrings::Etag,
"\"" + StringUtils::itoa(rid) + "\"");
}
@ -331,7 +331,7 @@ void RestVocbaseBaseHandler::generateDocument(VPackSlice const& input,
}
// and generate a response
createResponse(GeneralResponse::ResponseCode::OK);
setResponseCode(GeneralResponse::ResponseCode::OK);
// set ETAG header
if (!rev.empty()) {

View File

@ -154,14 +154,14 @@ class RestVocbaseBaseHandler : public RestBaseHandler {
//////////////////////////////////////////////////////////////////////////////
void generateOk() {
createResponse(GeneralResponse::ResponseCode::NO_CONTENT);
setResponseCode(GeneralResponse::ResponseCode::NO_CONTENT);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief generates ok message with no body but with certain status code
//////////////////////////////////////////////////////////////////////////////
void generateOk(GeneralResponse::ResponseCode code) { createResponse(code); }
void generateOk(GeneralResponse::ResponseCode code) { setResponseCode(code); }
//////////////////////////////////////////////////////////////////////////////
/// @brief generates message for a saved document