Skip to content

Commit 59f94fb

Browse files
committed
precondition if-none-match asterisk
1 parent 5a42a14 commit 59f94fb

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/create-app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const { routeResolvedFile } = require('./utils')
2727
const ResourceMapper = require('./resource-mapper')
2828
const aclCheck = require('@solid/acl-check')
2929
const { version } = require('../package.json')
30+
// const preconditions = require('express-preconditions')
3031

3132
const corsSettings = cors({
3233
methods: [

lib/handlers/put.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ async function putStream (req, res, next, stream = req) {
6464
try {
6565
// First check if the file already exists
6666
await ldp.resourceMapper.mapUrlToFile({ url: req })
67+
// Fails on if-none-match asterisk precondition
68+
if ((req.headers['if-none-match'] === '*') && !req.path.endsWith('/')) {
69+
res.sendStatus(412)
70+
return next()
71+
}
6772
} catch (err) {
6873
resourceExists = false
6974
}
7075
try {
76+
// Fails with Append on existing resource
7177
if (!req.originalUrl.endsWith('.acl')) await checkPermission(req, resourceExists)
7278
await ldp.put(req, stream, getContentType(req.headers))
7379
res.sendStatus(201)

test/integration/http-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,20 @@ describe('HTTP APIs', function () {
504504
'../resources/sampleContainer/put1.ttl'), {
505505
encoding: 'utf8'
506506
})
507-
it('should create new resource', function (done) {
507+
it('should create new resource with if-none-match on non existing resource', function (done) {
508508
server.put('/put-resource-1.ttl')
509509
.send(putRequestBody)
510+
.set('if-none-match', '*')
510511
.set('content-type', 'text/plain')
511512
.expect(201, done)
512513
})
514+
it('should fail with 412 with precondition on existing resource', function (done) {
515+
server.put('/put-resource-1.ttl')
516+
.send(putRequestBody)
517+
.set('if-none-match', '*')
518+
.set('content-type', 'text/plain')
519+
.expect(412, done)
520+
})
513521
it('should fail with 400 if not content-type', function (done) {
514522
server.put('/put-resource-1.ttl')
515523
.send(putRequestBody)

0 commit comments

Comments
 (0)