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
Changes from 3 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
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 = 204 // if content is sent back change to 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)
CxRes marked this conversation as resolved.
Show resolved Hide resolved
return next()
} catch (err) {
err.message = 'Can\'t write file/folder: ' + err.message
Expand Down
Loading