Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update put.js send 200 or 204 depending on pre-existance of resource #1785

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/handlers/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions test/integration/acl-oidc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down Expand Up @@ -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()
})
})
Expand All @@ -240,7 +240,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
options.body = '<a> <b> <c> .'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
assert.equal(response.statusCode, 204)
done()
})
})
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
'\n <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>.'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
assert.equal(response.statusCode, 204)
done()
})
})
Expand Down Expand Up @@ -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()
})
})
Expand Down Expand Up @@ -606,7 +606,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
options.body = '<a> <b> <c> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
assert.equal(response.statusCode, 204)
done()
})
})
Expand Down Expand Up @@ -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()
})
})
Expand All @@ -834,7 +834,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
options.body = '<a> <b> <c> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
assert.equal(response.statusCode, 204)
done()
})
})
Expand All @@ -860,7 +860,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
options.body = '<d> <e> <f> .\n'
request.put(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
assert.equal(response.statusCode, 204)
done()
})
})
Expand Down
14 changes: 7 additions & 7 deletions test/integration/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) {
Expand Down Expand Up @@ -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', '<http://www.w3.org/ns/ldp#BasicContainer>; 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', '<http://www.w3.org/ns/ldp#BasicContainer>; 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', '<http://www.w3.org/ns/ldp#BasicContainer>; 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',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/validate-tts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Loading