mirror of https://gitee.com/bigwinds/arangodb
added missing if none match header when reading nodes or edges (#6165)
This commit is contained in:
parent
ac2bd395cd
commit
bb3a6002b8
|
@ -276,7 +276,14 @@ void RestGraphHandler::vertexActionRead(
|
||||||
Graph& graph, std::string const& collectionName,
|
Graph& graph, std::string const& collectionName,
|
||||||
std::string const& key) {
|
std::string const& key) {
|
||||||
|
|
||||||
|
// check for an etag
|
||||||
bool isValidRevision;
|
bool isValidRevision;
|
||||||
|
TRI_voc_rid_t ifNoneRid = extractRevision("if-none-match", isValidRevision);
|
||||||
|
if (!isValidRevision) {
|
||||||
|
ifNoneRid =
|
||||||
|
UINT64_MAX; // an impossible rev, so precondition failed will happen
|
||||||
|
}
|
||||||
|
|
||||||
TRI_voc_rid_t revision = extractRevision("if-match", isValidRevision);
|
TRI_voc_rid_t revision = extractRevision("if-match", isValidRevision);
|
||||||
if (!isValidRevision) {
|
if (!isValidRevision) {
|
||||||
revision =
|
revision =
|
||||||
|
@ -298,6 +305,14 @@ void RestGraphHandler::vertexActionRead(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ifNoneRid != 0) {
|
||||||
|
TRI_voc_rid_t const rid = TRI_ExtractRevisionId(result.slice());
|
||||||
|
if (ifNoneRid == rid) {
|
||||||
|
generateNotModified(rid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto ctx = std::make_shared<transaction::StandaloneContext>(_vocbase);
|
auto ctx = std::make_shared<transaction::StandaloneContext>(_vocbase);
|
||||||
// use default options
|
// use default options
|
||||||
generateVertexRead(result.slice(), *ctx->getVPackOptionsForDump());
|
generateVertexRead(result.slice(), *ctx->getVPackOptionsForDump());
|
||||||
|
@ -542,7 +557,14 @@ void RestGraphHandler::edgeActionRead(
|
||||||
Graph& graph,
|
Graph& graph,
|
||||||
const std::string &definitionName, const std::string &key) {
|
const std::string &definitionName, const std::string &key) {
|
||||||
|
|
||||||
|
// check for an etag
|
||||||
bool isValidRevision;
|
bool isValidRevision;
|
||||||
|
TRI_voc_rid_t ifNoneRid = extractRevision("if-none-match", isValidRevision);
|
||||||
|
if (!isValidRevision) {
|
||||||
|
ifNoneRid =
|
||||||
|
UINT64_MAX; // an impossible rev, so precondition failed will happen
|
||||||
|
}
|
||||||
|
|
||||||
TRI_voc_rid_t revision = extractRevision("if-match", isValidRevision);
|
TRI_voc_rid_t revision = extractRevision("if-match", isValidRevision);
|
||||||
if (!isValidRevision) {
|
if (!isValidRevision) {
|
||||||
revision =
|
revision =
|
||||||
|
@ -558,6 +580,14 @@ void RestGraphHandler::edgeActionRead(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ifNoneRid != 0) {
|
||||||
|
TRI_voc_rid_t const rid = TRI_ExtractRevisionId(result.slice());
|
||||||
|
if (ifNoneRid == rid) {
|
||||||
|
generateNotModified(rid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto ctx = std::make_shared<transaction::StandaloneContext>(_vocbase);
|
auto ctx = std::make_shared<transaction::StandaloneContext>(_vocbase);
|
||||||
generateEdgeRead(result.slice(), *ctx->getVPackOptionsForDump());
|
generateEdgeRead(result.slice(), *ctx->getVPackOptionsForDump());
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,6 @@ describe('_api/gharial', () => {
|
||||||
|
|
||||||
afterEach(cleanup);
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
|
||||||
it('should create a graph without orphans', () => {
|
it('should create a graph without orphans', () => {
|
||||||
const graphDef = {
|
const graphDef = {
|
||||||
"name": graphName,
|
"name": graphName,
|
||||||
|
@ -608,4 +607,116 @@ describe('_api/gharial', () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should check if the if-match header is working - positive', () => {
|
||||||
|
const examples = require('@arangodb/graph-examples/example-graph');
|
||||||
|
const exampleGraphName = 'knows_graph';
|
||||||
|
const vName = 'persons';
|
||||||
|
const eName = 'knows';
|
||||||
|
expect(db._collection(eName)).to.be.null; // edgec
|
||||||
|
expect(db._collection(vName)).to.be.null; // vertexc
|
||||||
|
const g = examples.loadGraph(exampleGraphName);
|
||||||
|
expect(g).to.not.be.null;
|
||||||
|
expect(db._collection(eName)).to.not.be.null;
|
||||||
|
expect(db._collection(vName)).to.not.be.null;
|
||||||
|
|
||||||
|
const key = 'bob';
|
||||||
|
const doc = db[vName].document(key);
|
||||||
|
const revision = doc._rev; // get a valid revision
|
||||||
|
|
||||||
|
let req = request.get(url + '/' + exampleGraphName + '/edge/' + vName + '/' + key , {
|
||||||
|
headers: {
|
||||||
|
'if-match': revision
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(req.statusCode).to.equal(200);
|
||||||
|
expect(req.json.edge).to.deep.equal(doc);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should check if the if-match header is working - negative', () => {
|
||||||
|
const examples = require('@arangodb/graph-examples/example-graph');
|
||||||
|
const exampleGraphName = 'knows_graph';
|
||||||
|
const vName = 'persons';
|
||||||
|
const eName = 'knows';
|
||||||
|
expect(db._collection(eName)).to.be.null; // edgec
|
||||||
|
expect(db._collection(vName)).to.be.null; // vertexc
|
||||||
|
const g = examples.loadGraph(exampleGraphName);
|
||||||
|
expect(g).to.not.be.null;
|
||||||
|
expect(db._collection(eName)).to.not.be.null;
|
||||||
|
expect(db._collection(vName)).to.not.be.null;
|
||||||
|
|
||||||
|
const key = 'bob';
|
||||||
|
const doc = db[vName].document(key);
|
||||||
|
let revision = doc._rev; // get a valid revision
|
||||||
|
revision = revision + 'x';
|
||||||
|
|
||||||
|
const revisions = [null, undefined, true, false, revision];
|
||||||
|
|
||||||
|
revisions.forEach(function (rev) {
|
||||||
|
let req = request.get(url + '/' + exampleGraphName + '/edge/' + vName + '/' + key , {
|
||||||
|
headers: {
|
||||||
|
'if-match': rev
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(req.json.error).to.equal(true);
|
||||||
|
expect(req.statusCode).to.equal(ERRORS.ERROR_HTTP_PRECONDITION_FAILED.code);
|
||||||
|
expect(req.json.code).to.equal(ERRORS.ERROR_HTTP_PRECONDITION_FAILED.code);
|
||||||
|
expect(req.json.errorMessage).to.equal(ERRORS.ERROR_HTTP_PRECONDITION_FAILED.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should check if the if-none-match header is working - positive', () => {
|
||||||
|
const examples = require('@arangodb/graph-examples/example-graph');
|
||||||
|
const exampleGraphName = 'knows_graph';
|
||||||
|
const vName = 'persons';
|
||||||
|
const eName = 'knows';
|
||||||
|
expect(db._collection(eName)).to.be.null; // edgec
|
||||||
|
expect(db._collection(vName)).to.be.null; // vertexc
|
||||||
|
const g = examples.loadGraph(exampleGraphName);
|
||||||
|
expect(g).to.not.be.null;
|
||||||
|
expect(db._collection(eName)).to.not.be.null;
|
||||||
|
expect(db._collection(vName)).to.not.be.null;
|
||||||
|
|
||||||
|
const key = 'bob';
|
||||||
|
const doc = db[vName].document(key);
|
||||||
|
const revision = doc._rev; // get a valid revision
|
||||||
|
|
||||||
|
let req = request.get(url + '/' + exampleGraphName + '/edge/' + vName + '/' + key , {
|
||||||
|
headers: {
|
||||||
|
'if-none-match': revision
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(req.status).to.equal(304);
|
||||||
|
expect(req.json).to.equal(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should check if the if-none-match header is working - negative', () => {
|
||||||
|
const examples = require('@arangodb/graph-examples/example-graph');
|
||||||
|
const exampleGraphName = 'knows_graph';
|
||||||
|
const vName = 'persons';
|
||||||
|
const eName = 'knows';
|
||||||
|
expect(db._collection(eName)).to.be.null; // edgec
|
||||||
|
expect(db._collection(vName)).to.be.null; // vertexc
|
||||||
|
const g = examples.loadGraph(exampleGraphName);
|
||||||
|
expect(g).to.not.be.null;
|
||||||
|
expect(db._collection(eName)).to.not.be.null;
|
||||||
|
expect(db._collection(vName)).to.not.be.null;
|
||||||
|
|
||||||
|
const key = 'bob';
|
||||||
|
const doc = db[vName].document(key);
|
||||||
|
let revision = doc._rev; // get a valid revision
|
||||||
|
revision = revision + 'x';
|
||||||
|
|
||||||
|
const revisions = [null, undefined, true, false, revision];
|
||||||
|
|
||||||
|
revisions.forEach(function (rev) {
|
||||||
|
let req = request.get(url + '/' + exampleGraphName + '/edge/' + vName + '/' + key , {
|
||||||
|
headers: {
|
||||||
|
'if-none-match': rev
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(req.statusCode).to.equal(200);
|
||||||
|
expect(req.json.edge).to.deep.equal(doc);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue