Skip to content

Commit 5e71231

Browse files
authored
Update put.js send 200 or 201 depending on prexistance of resource
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.
1 parent 07ee53c commit 5e71231

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/handlers/put.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async function putStream (req, res, next, stream = req) {
6262
// try {
6363
// Obtain details of the target resource
6464
let resourceExists = true
65+
let returnStatus = 201;
6566
try {
6667
// First check if the file already exists
6768
await ldp.resourceMapper.mapUrlToFile({ url: req })
@@ -70,14 +71,15 @@ async function putStream (req, res, next, stream = req) {
7071
res.sendStatus(412)
7172
return next()
7273
}
74+
returnStatus = 200;
7375
} catch (err) {
7476
resourceExists = false
7577
}
7678
try {
7779
// Fails with Append on existing resource
7880
if (!req.originalUrl.endsWith('.acl')) await checkPermission(req, resourceExists)
7981
await ldp.put(req, stream, getContentType(req.headers))
80-
res.sendStatus(201)
82+
res.sendStatus(returnStatus)
8183
return next()
8284
} catch (err) {
8385
err.message = 'Can\'t write file/folder: ' + err.message

0 commit comments

Comments
 (0)