Skip to content

Commit 4fa4cf5

Browse files
author
nicola
committed
adding next to every call, fixing get/head
1 parent bd64ba7 commit 4fa4cf5

7 files changed

Lines changed: 30 additions & 52 deletions

File tree

‎lib/handlers/delete.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function handler(req, res, next) {
2020
}
2121

2222
debug("DELETE -- Ok.");
23-
if (ldp.live) ldp.live(utils.uriAbs(req) + path.basename(req.originalUrl))
24-
if (ldp.live) ldp.live(utils.uriAbs(req) + req.originalUrl)
25-
return res.sendStatus(200);
23+
24+
res.sendStatus(200);
25+
return next();
2626
});
2727

2828
}

‎lib/handlers/get.js‎

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@ var HttpError = require('../http-error');
2020

2121
var ldpVocab = require('../vocab/ldp.js');
2222

23-
function get(req, res, next, includeBody) {
23+
function get(req, res, next) {
2424
var ldp = req.app.locals.ldp;
2525
var uri = utils.uriBase(req);
2626
var filename = utils.uriToFilename(req.path, ldp.root);
2727

28-
// // Add request to subscription service
29-
// if (req.path.slice(-ldp.suffixChanges.length) ===
30-
// ldp.suffixChanges) {
31-
// debug("GET -- Subscribed to " + req.originalUrl);
32-
// return subscription.subscribeToChanges(req, res);
33-
// }
28+
var includeBody = req.method === 'GET'
3429

3530
// Parse accept mime types into a priority (q) ordered array
3631
res.acceptTypes = header.negotiateContentType(req) || 'text/turtle';
@@ -40,19 +35,10 @@ function get(req, res, next, includeBody) {
4035

4136
// Set live updates
4237
if (ldp.live) {
43-
// Note not yet in
44-
// http://www.iana.org/assignments/link-relations/link-relations.xhtml
45-
// header.addLink(res, req.originalUrl + ldp.suffixChanges, 'changes');
46-
// res.header('Link' , '' + req.path + ldp.suffixSSE + ' ; rel=events' );
47-
// overwrites the pevious
4838
res.header('Updates-Via', utils.uriBase(req));
4939
}
5040

51-
if (includeBody) {
52-
debug('GET -- ' + req.originalUrl);
53-
} else {
54-
debug('HEAD -- ' + req.originalUrl);
55-
}
41+
debug(req.method + ' -- ' + req.originalUrl);
5642

5743
// Get resource or container
5844
ldp.get(filename, uri, includeBody, function(err, data, container) {
@@ -72,7 +58,8 @@ function get(req, res, next, includeBody) {
7258
// Just return that file exists
7359
// data is of `typeof 'string'` if file is empty, but exists!
7460
if (data === undefined) {
75-
return res.sendStatus(200);
61+
res.sendStatus(200);
62+
return next();
7663
}
7764

7865
// Container/resource retrieved
@@ -87,9 +74,10 @@ function get(req, res, next, includeBody) {
8774

8875
// if data is not text/turtle, just send it
8976
if (contentType !== 'text/turtle') {
90-
return res
77+
res
9178
.status(200)
9279
.send(data);
80+
return next();
9381
}
9482
}
9583

@@ -192,9 +180,10 @@ function parseLinkedData(req, res, next) {
192180
accept === 'text/n3' ||
193181
accept === 'application/turtle' ||
194182
accept === 'application/n3') {
195-
return res.status(200)
183+
res.status(200)
196184
.set('content-type', accept)
197185
.send(turtleData);
186+
return next();
198187
}
199188

200189
//Handle other file types
@@ -219,21 +208,13 @@ function parseLinkedData(req, res, next) {
219208
status: 500
220209
}));
221210
}
222-
223-
return res
211+
res
224212
.status(200)
225213
.set('content-type', accept)
226214
.send(result);
227-
});
228-
}
229215

230-
function getHandler(req, res, next) {
231-
get(req, res, next, true);
232-
}
233-
234-
function headHandler(req, res, next) {
235-
get(req, res, next, false);
216+
return next();
217+
});
236218
}
237219

238-
exports.handler = getHandler;
239-
exports.headHandler = headHandler;
220+
exports.handler = get;

‎lib/handlers/patch.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function handler(req, res, next) {
2727
if (patchContentType === 'application/sparql') {
2828
sparql(filename, targetURI, req.text, function(err, result) {
2929
if (err) {
30-
next(err);
30+
return next(err);
3131
}
3232

33-
if (ldp.live) ldp.live(utils.uriAbs(req) + req.originalUrl)
34-
return res.json(result);
33+
res.json(result);
34+
return next();
3535
});
3636
} else
3737
if (patchContentType === 'application/sparql-update') {
@@ -40,10 +40,10 @@ function handler(req, res, next) {
4040
return next(err);
4141
}
4242

43-
if (ldp.live) ldp.live(utils.uriAbs(req) + req.originalUrl)
4443
// subscription.publishDelta(req, res, patchKB, targetURI);
4544
debug("PATCH -- applied OK (sync)");
4645
res.send("Patch applied OK\n");
46+
return next()
4747
});
4848
} else {
4949
return next(new HttpError({

‎lib/handlers/post.js‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ function handler(req, res, next) {
2222
// Handle SPARQL query
2323
if (contentType === 'application/sparql') {
2424
debug("POST -- Handling sparql query");
25-
return patch.handler(req, res);
25+
return patch.handler(req, res, next);
2626
}
2727

2828
// Handle SPARQL-update query
2929
if (contentType === 'application/sparql-update') {
3030
debug("POST -- Handling sparql-update query");
31-
return patch.handler(req, res);
31+
return patch.handler(req, res, next);
3232
}
3333

3434
// Error on invalid content-type
@@ -133,8 +133,8 @@ function handler(req, res, next) {
133133

134134
debug("POST -- Created new container " + resourceBaseUri);
135135
res.set('Location', resourceBaseUri);
136-
if (ldp.live) ldp.live(utils.uriAbs(req) + path.basename(req.originalUrl))
137-
return res.sendStatus(201);
136+
res.sendStatus(201);
137+
return next();
138138
}
139139

140140
function resourceCallback(err) {
@@ -143,9 +143,8 @@ function handler(req, res, next) {
143143
return next(err);
144144
}
145145
res.set('Location', resourceBaseUri);
146-
if (ldp.live) ldp.live(utils.uriAbs(req) + req.originalUrl)
147-
if (ldp.live) ldp.live(utils.uriAbs(req) + path.basename(req.originalUrl))
148-
return res.sendStatus(201);
146+
res.sendStatus(201);
147+
return next();
149148
}
150149
}
151150

‎lib/handlers/put.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function handler(req, res, next) {
2727

2828
debug("PUT -- Write Ok. Bytes written: " + req.text.length);
2929

30-
if (ldp.live) ldp.live(utils.uriAbs(req) + req.originalUrl)
31-
return res.sendStatus(201);
30+
res.sendStatus(201);
31+
return next();
3232
});
3333
}
3434

‎lib/ldp-middleware.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function LdpMiddleware (corsSettings) {
4545

4646
//ACL handlers
4747
router.get("/*", acl.allowReadHandler);
48-
router.head("/*", acl.allowReadHandler);
4948
router.post("/*", acl.allowAppendThenWriteHandler);
5049
router.patch("/*", acl.allowAppendThenWriteHandler);
5150
router.put("/*", acl.allowAppendThenWriteHandler);
@@ -59,7 +58,6 @@ function LdpMiddleware (corsSettings) {
5958

6059
// HTTP methods handlers
6160
router.get('/*', getHandler.handler);
62-
router.head('/*', getHandler.headHandler);
6361
router.put('/*', putHandler.handler);
6462
router.delete('/*', deleteHandler.handler);
6563
router.post('/*', postHandler.handler);

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"async": "^1.3.0",
2929
"cors": "^2.7.1",
3030
"debug": "^2.2.0",
31-
"express": "^4.13.1",
31+
"express": "^4.13.3",
3232
"express-session": "^1.11.3",
3333
"fs-extra": "^0.21.0",
3434
"glob": "^5.0.13",
@@ -46,7 +46,7 @@
4646
"redis": "^0.12.1",
4747
"request": "^2.58.0",
4848
"response-time": "^2.3.1",
49-
"solid-ws": "^0.1.5",
49+
"solid-ws": "^0.2.0",
5050
"string": "^3.3.0",
5151
"webid": "^0.2.4"
5252
},

0 commit comments

Comments
 (0)