The 423 Locked
status code is part of the Web Distributed Authoring and Versioning (WebDAV) extension to the HTTP/1.1 protocol. It indicates that the resource being accessed is locked and the requested action cannot be performed until the lock is released. This status code is typically used in collaborative environments where multiple users might be working on the same resource, and a locking mechanism is employed to prevent conflicts or loss of data.
When to Use 423 Locked
You should return the 423 Locked
status code when a client attempts to perform an action on a resource that is currently locked by another client. The lock could be either an exclusive lock, where only the lock owner can perform actions on the resource, or a shared lock, where multiple clients can access the resource concurrently but with restricted actions.
Common scenarios where 423 Locked
might be used include:
- A user attempting to edit a document that is currently being edited by another user.
- A client trying to delete a file that is locked by a backup process.
Request and Response Examples
Example 1: Attempting to Edit a Locked Document
In this example, a client tries to update a document that is locked by another user. The server responds with a 423 Locked
status code.
Request:
PUT /documents/document1.txt HTTP/1.1
Host: example.com
Content-Type: text/plain
Content-Length: 15
New content here
Response:
HTTP/1.1 423 Locked
Content-Type: text/plain
Content-Length: 44
The document is locked by another user. Try later.
Example 2: Attempting to Delete a Locked File
In this example, a client tries to delete a file that is locked by a backup process. The server responds with a 423 Locked
status code.
Request:
DELETE /files/important-file.txt HTTP/1.1
Host: example.com
Response:
HTTP/1.1 423 Locked
Content-Type: text/plain
Content-Length: 40
The file is locked by a backup process. Try later.
Handling 423 Locked
When encountering a 423 Locked
status code, clients should inform the user about the locked state of the resource and provide options to either retry the action later or cancel the operation. In some cases, it might be useful to provide additional information about the lock, such as the lock owner or the expected time for the lock to be released.
Summary
The 423 Locked
HTTP status code is part of the WebDAV extension and indicates that the requested action cannot be performed on a locked resource. It is commonly used in collaborative environments to prevent conflicts and data loss. When encountering this status code, clients should inform the user about the locked state and provide options to retry the action later or cancel the operation.