Skip to content

423 Locked (WebDAV; HTTP Status Code 423)

Updated: at 09:12 AM

HTTP status code 423 means “Locked.” This status code was originally defined in the WebDAV (Web Distributed Authoring and Versioning) protocol to handle concurrency issues in distributed file systems. The 423 Locked status code indicates that the requested resource is currently locked and cannot be accessed.

Main Uses

Use Cases

Application in WebDAV

In WebDAV, the 423 status code is typically used with the LOCK and UNLOCK methods to manage the locking state of resources.

Response Format

When returning a 423 status code, the server should generally provide additional information, such as:

Client Handling

Upon receiving a 423 response, the client should:

Example Scenario

const fileLocks = new Map();

app.put("/api/files/:id/edit", (req, res) => {
  const fileId = req.params.id;
  const userId = req.user.id; // Assume user authentication is implemented

  if (fileLocks.has(fileId)) {
    const lock = fileLocks.get(fileId);
    if (lock.userId !== userId) {
      return res.status(423).json({
        error: "Locked",
        message: "This file is currently being edited by another user.",
        lockedBy: lock.userId,
        lockedAt: lock.timestamp,
        retryAfter: 300, // Suggest retry after 5 minutes
      });
    }
  }

  // Lock the file for this user
  fileLocks.set(fileId, { userId, timestamp: new Date() });

  // Proceed with file editing...
  res.json({ message: "File locked for editing" });
});

app.put("/api/files/:id/release", (req, res) => {
  const fileId = req.params.id;
  const userId = req.user.id;

  if (fileLocks.has(fileId) && fileLocks.get(fileId).userId === userId) {
    fileLocks.delete(fileId);
    res.json({ message: "File lock released" });
  } else {
    res.status(400).json({
      error: "Bad Request",
      message: "No lock exists for this file and user",
    });
  }
});