Skip to content

Commit f589a20

Browse files
authored
Merge pull request #1785 from nodeSolidServer/jeff-zucker-patch-1
Update put.js send 200 or 204 depending on pre-existance of resource
2 parents 07ee53c + 43bf813 commit f589a20

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

lib/handlers/put.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function putStream (req, res, next, stream = req) {
7777
// Fails with Append on existing resource
7878
if (!req.originalUrl.endsWith('.acl')) await checkPermission(req, resourceExists)
7979
await ldp.put(req, stream, getContentType(req.headers))
80-
res.sendStatus(201)
80+
res.sendStatus(resourceExists ? 204 : 201)
8181
return next()
8282
} catch (err) {
8383
err.message = 'Can\'t write file/folder: ' + err.message

test/integration/acl-oidc-test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
143143
options.body = ''
144144
request.put(options, function (error, response, body) {
145145
assert.equal(error, null)
146-
assert.equal(response.statusCode, 201)
146+
assert.equal(response.statusCode, 204)
147147
done()
148148
})
149149
})
@@ -214,7 +214,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
214214
options.body = ''
215215
request.put(options, function (error, response, body) {
216216
assert.equal(error, null)
217-
assert.equal(response.statusCode, 201) // 403) is this a must ?
217+
assert.equal(response.statusCode, 204) // 403) is this a must ?
218218
done()
219219
})
220220
})
@@ -240,7 +240,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
240240
options.body = '<a> <b> <c> .'
241241
request.put(options, function (error, response, body) {
242242
assert.equal(error, null)
243-
assert.equal(response.statusCode, 201)
243+
assert.equal(response.statusCode, 204)
244244
done()
245245
})
246246
})
@@ -283,7 +283,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
283283
'\n <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>.'
284284
request.put(options, function (error, response, body) {
285285
assert.equal(error, null)
286-
assert.equal(response.statusCode, 201)
286+
assert.equal(response.statusCode, 204)
287287
done()
288288
})
289289
})
@@ -456,7 +456,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
456456
options.body = body
457457
request.put(options, function (error, response, body) {
458458
assert.equal(error, null)
459-
assert.equal(response.statusCode, 201)
459+
assert.equal(response.statusCode, 204)
460460
done()
461461
})
462462
})
@@ -606,7 +606,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
606606
options.body = '<a> <b> <c> .\n'
607607
request.put(options, function (error, response, body) {
608608
assert.equal(error, null)
609-
assert.equal(response.statusCode, 201)
609+
assert.equal(response.statusCode, 204)
610610
done()
611611
})
612612
})
@@ -809,7 +809,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
809809
options.body = body
810810
request.put(options, function (error, response, body) {
811811
assert.equal(error, null)
812-
assert.equal(response.statusCode, 201)
812+
assert.equal(response.statusCode, 204)
813813
done()
814814
})
815815
})
@@ -834,7 +834,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
834834
options.body = '<a> <b> <c> .\n'
835835
request.put(options, function (error, response, body) {
836836
assert.equal(error, null)
837-
assert.equal(response.statusCode, 201)
837+
assert.equal(response.statusCode, 204)
838838
done()
839839
})
840840
})
@@ -860,7 +860,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
860860
options.body = '<d> <e> <f> .\n'
861861
request.put(options, function (error, response, body) {
862862
assert.equal(error, null)
863-
assert.equal(response.statusCode, 201)
863+
assert.equal(response.statusCode, 204)
864864
done()
865865
})
866866
})

test/integration/http-test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ describe('HTTP APIs', function () {
565565
server.put('/put-resource-1.ttl')
566566
.send(putRequestBody)
567567
.set('content-type', 'text/turtle')
568-
.expect(201)
568+
.expect(204)
569569
.end(function (err) {
570570
if (err) return done(err)
571571
if (fs.existsSync(path.join(__dirname, '../resources/put-resource-1.ttl$.txt'))) {
@@ -646,28 +646,28 @@ describe('HTTP APIs', function () {
646646
.expect(201, done)
647647
}
648648
)
649-
it('should return 201 code when trying to put to a container',
649+
it('should return 204 code when trying to put to a container',
650650
function (done) {
651651
server.put('/foo/bar/test/')
652652
.set('content-type', 'text/turtle')
653653
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
654-
.expect(201, done)
654+
.expect(204, done)
655655
}
656656
)
657-
it('should return 201 when trying to put to a container without content-type',
657+
it('should return 204 when trying to put to a container without content-type',
658658
function (done) {
659659
server.put('/foo/bar/test/')
660660
// .set('content-type', 'text/turtle')
661661
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
662-
.expect(201, done)
662+
.expect(204, done)
663663
}
664664
)
665-
it('should return 201 code when trying to put to a container',
665+
it('should return 204 code when trying to put to a container',
666666
function (done) {
667667
server.put('/foo/bar/test/')
668668
.set('content-type', 'text/turtle')
669669
.set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"')
670-
.expect(201, done)
670+
.expect(204, done)
671671
}
672672
)
673673
it('should return a 400 error when trying to PUT a container with a name that contains a reserved suffix',

test/integration/validate-tts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('HTTP requests with invalid Turtle syntax', () => {
2020
server.put('/invalid1.ttl')
2121
.send(invalidTurtleBody)
2222
.set('content-type', 'text/turtle')
23-
.expect(201, done)
23+
.expect(204, done)
2424
})
2525

2626
it('is not allowed with invalid ACL files', (done) => {

0 commit comments

Comments
 (0)