diff --git a/lib/handlers/put.js b/lib/handlers/put.js index 740bf346..ba698ff9 100644 --- a/lib/handlers/put.js +++ b/lib/handlers/put.js @@ -77,7 +77,7 @@ async function putStream (req, res, next, stream = req) { // Fails with Append on existing resource if (!req.originalUrl.endsWith('.acl')) await checkPermission(req, resourceExists) await ldp.put(req, stream, getContentType(req.headers)) - res.sendStatus(201) + res.sendStatus(resourceExists ? 204 : 201) return next() } catch (err) { err.message = 'Can\'t write file/folder: ' + err.message diff --git a/test/integration/acl-oidc-test.js b/test/integration/acl-oidc-test.js index 1de13539..77919a35 100644 --- a/test/integration/acl-oidc-test.js +++ b/test/integration/acl-oidc-test.js @@ -143,7 +143,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = '' request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) @@ -214,7 +214,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = '' request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) // 403) is this a must ? + assert.equal(response.statusCode, 204) // 403) is this a must ? done() }) }) @@ -240,7 +240,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = ' .' request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) @@ -283,7 +283,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { '\n .' request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) @@ -456,7 +456,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = body request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) @@ -606,7 +606,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = ' .\n' request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) @@ -809,7 +809,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = body request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) @@ -834,7 +834,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = ' .\n' request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) @@ -860,7 +860,7 @@ describe('ACL with WebID+OIDC over HTTP', function () { options.body = ' .\n' request.put(options, function (error, response, body) { assert.equal(error, null) - assert.equal(response.statusCode, 201) + assert.equal(response.statusCode, 204) done() }) }) diff --git a/test/integration/http-test.js b/test/integration/http-test.js index 4e5d599f..58c9f714 100644 --- a/test/integration/http-test.js +++ b/test/integration/http-test.js @@ -565,7 +565,7 @@ describe('HTTP APIs', function () { server.put('/put-resource-1.ttl') .send(putRequestBody) .set('content-type', 'text/turtle') - .expect(201) + .expect(204) .end(function (err) { if (err) return done(err) if (fs.existsSync(path.join(__dirname, '../resources/put-resource-1.ttl$.txt'))) { @@ -646,28 +646,28 @@ describe('HTTP APIs', function () { .expect(201, done) } ) - it('should return 201 code when trying to put to a container', + it('should return 204 code when trying to put to a container', function (done) { server.put('/foo/bar/test/') .set('content-type', 'text/turtle') .set('link', '; rel="type"') - .expect(201, done) + .expect(204, done) } ) - it('should return 201 when trying to put to a container without content-type', + it('should return 204 when trying to put to a container without content-type', function (done) { server.put('/foo/bar/test/') // .set('content-type', 'text/turtle') .set('link', '; rel="type"') - .expect(201, done) + .expect(204, done) } ) - it('should return 201 code when trying to put to a container', + it('should return 204 code when trying to put to a container', function (done) { server.put('/foo/bar/test/') .set('content-type', 'text/turtle') .set('link', '; rel="type"') - .expect(201, done) + .expect(204, done) } ) it('should return a 400 error when trying to PUT a container with a name that contains a reserved suffix', diff --git a/test/integration/validate-tts.js b/test/integration/validate-tts.js index ae4d5e2d..cd24c38c 100644 --- a/test/integration/validate-tts.js +++ b/test/integration/validate-tts.js @@ -20,7 +20,7 @@ describe('HTTP requests with invalid Turtle syntax', () => { server.put('/invalid1.ttl') .send(invalidTurtleBody) .set('content-type', 'text/turtle') - .expect(201, done) + .expect(204, done) }) it('is not allowed with invalid ACL files', (done) => {