Skip to content

Commit 6c31436

Browse files
committed
feat/refactor: Event-ID Generated for Notifications Only
+ Event-ID is generated in PREP notification middleware itself. + No longer setting `Event-ID` response header upon resource mutation, thus reverting the middlewares for unsafe methods to their original state, before PREP was introduced.
1 parent c33bc32 commit 6c31436

File tree

5 files changed

+1
-16
lines changed

5 files changed

+1
-16
lines changed

lib/handlers/delete.js

-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ async function handler (req, res, next) {
66
debug('DELETE -- Request on' + req.originalUrl)
77

88
const ldp = req.app.locals.ldp
9-
const prep = req.app.locals.prep
109
try {
1110
await ldp.delete(req)
1211
debug('DELETE -- Ok.')
13-
// Add event-id for notifications
14-
prep && res.setHeader('Event-ID', res.setEventID())
1512
res.sendStatus(200)
1613
next()
1714
} catch (err) {

lib/handlers/notify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function handler (req, res, next) {
5858

5959
const { method, path } = req
6060
const { statusCode } = res
61-
const eventID = res.getHeader('event-id')
61+
const eventID = res.setEventID()
6262
const fullUrl = new URL(path, `${req.protocol}://${req.hostname}/`)
6363

6464
// Date is a hack since node does not seem to provide access to send date.

lib/handlers/patch.js

-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function contentForNew (contentType) {
3939
// Handles a PATCH request
4040
async function patchHandler (req, res, next) {
4141
debug(`PATCH -- ${req.originalUrl}`)
42-
const prep = req.app.locals.prep
4342
try {
4443
// Obtain details of the target resource
4544
const ldp = req.app.locals.ldp
@@ -91,9 +90,6 @@ async function patchHandler (req, res, next) {
9190
await applyPatch(patchObject, graph, url)
9291
return writeGraph(graph, resource, ldp.resourceMapper.resolveFilePath(req.hostname), ldp.serverUri)
9392
})
94-
95-
// Add event-id for notifications
96-
prep && res.setHeader('Event-ID', res.setEventID())
9793
// Send the status and result to the client
9894
res.status(resourceExists ? 200 : 201)
9995
res.send(result)

lib/handlers/post.js

-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const getContentType = require('../utils').getContentType
1111

1212
async function handler (req, res, next) {
1313
const ldp = req.app.locals.ldp
14-
const prep = req.app.locals.prep
1514
const contentType = getContentType(req.headers)
1615
debug('content-type is ', contentType)
1716
// Handle SPARQL(-update?) query
@@ -73,8 +72,6 @@ async function handler (req, res, next) {
7372
// Handled by backpressure of streams!
7473
busboy.on('finish', function () {
7574
debug('Done storing files')
76-
// Add event-id for notifications
77-
prep && res.setHeader('Event-ID', res.setEventID())
7875
res.sendStatus(200)
7976
next()
8077
})
@@ -94,8 +91,6 @@ async function handler (req, res, next) {
9491
debug('File stored in ' + resourcePath)
9592
header.addLinks(res, links)
9693
res.set('Location', resourcePath)
97-
// Add event-id for notifications
98-
prep && res.setHeader('Event-ID', res.setEventID())
9994
res.sendStatus(201)
10095
next()
10196
},

lib/handlers/put.js

-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ async function checkPermission (request, resourceExists) {
5959
// TODO could be renamed as putResource (it now covers container and non-container)
6060
async function putStream (req, res, next, stream = req) {
6161
const ldp = req.app.locals.ldp
62-
const prep = req.app.locals.prep
6362
// try {
6463
// Obtain details of the target resource
6564
let resourceExists = true
@@ -78,8 +77,6 @@ async function putStream (req, res, next, stream = req) {
7877
// Fails with Append on existing resource
7978
if (!req.originalUrl.endsWith('.acl')) await checkPermission(req, resourceExists)
8079
await ldp.put(req, stream, getContentType(req.headers))
81-
// Add event-id for notifications
82-
prep && res.setHeader('Event-ID', res.setEventID())
8380
res.sendStatus(resourceExists ? 204 : 201)
8481
return next()
8582
} catch (err) {

0 commit comments

Comments
 (0)