Skip to content

Commit

Permalink
Update put.js send 200 or 201 depending on prexistance of resource
Browse files Browse the repository at this point in the history
The HTTP spec says that the Server MUST return a 200 or 204 if PUT replaces and existing resource.  See second paragraph of https://httpwg.org/specs/rfc9110#PUT.

Brought up by @CxRes.
  • Loading branch information
jeff-zucker authored May 24, 2024
1 parent 07ee53c commit 5e71231
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/handlers/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async function putStream (req, res, next, stream = req) {
// try {
// Obtain details of the target resource
let resourceExists = true
let returnStatus = 201;
try {
// First check if the file already exists
await ldp.resourceMapper.mapUrlToFile({ url: req })
Expand All @@ -70,14 +71,15 @@ async function putStream (req, res, next, stream = req) {
res.sendStatus(412)
return next()
}
returnStatus = 200;
} catch (err) {
resourceExists = false
}
try {
// 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(returnStatus)
return next()
} catch (err) {
err.message = 'Can\'t write file/folder: ' + err.message
Expand Down

0 comments on commit 5e71231

Please sign in to comment.