423 Locked
Description
The 423 Locked
status code indicates that the resource that is being accessed is locked. This status code is primarily used in WebDAV (Web Distributed Authoring and Versioning) environments, where it indicates that the source or destination resource of a method is locked.
This status code is commonly used when: - A client attempts to modify a resource that has been locked by another client - A client attempts to access a resource that is currently undergoing maintenance - A client attempts to modify a resource that is part of a transaction or workflow that requires locking - A resource is temporarily locked for exclusive access
The 423 Locked
status helps prevent conflicts and data corruption in collaborative environments by ensuring that only one client can modify a resource at a time.
Syntax
The server responds with a 423 Locked
status:
HTTP/1.1 423 Locked
Content-Type: application/xml
Content-Length: [length in bytes]
<?xml version="1.0" encoding="UTF-8"?>
<d:error xmlns:d="DAV:">
<d:lock-token-submitted/>
</d:error>
For non-WebDAV applications, a JSON response might be used:
HTTP/1.1 423 Locked
Content-Type: application/json
Content-Length: [length in bytes]
{
"error": "Locked",
"message": "The resource you are trying to access is locked"
}
Examples
WebDAV Lock Example
A client attempts to modify a document that is locked by another user:
Client Request:
PUT /documents/report.docx HTTP/1.1
Host: webdav.example.com
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Length: 24680
[Document binary data]
Server Response:
HTTP/1.1 423 Locked
Content-Type: application/xml
Content-Length: 358
<?xml version="1.0" encoding="UTF-8"?>
<d:error xmlns:d="DAV:">
<d:lock-token-submitted/>
<d:detail>
<d:lockinfo>
<d:lockscope><d:exclusive/></d:lockscope>
<d:locktype><d:write/></d:locktype>
<d:owner>Jane Smith ([email protected])</d:owner>
<d:timeout>Second-3600</d:timeout>
</d:lockinfo>
</d:detail>
</d:error>
API Resource Lock Example
A client attempts to update a resource that is locked for maintenance:
Client Request:
PATCH /api/settings HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 45
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{
"maintenance_mode": false,
"debug_level": "info"
}
Server Response:
HTTP/1.1 423 Locked
Content-Type: application/json
Content-Length: 187
{
"error": "Locked",
"message": "System settings are currently locked for maintenance",
"locked_until": "2023-06-15T15:30:00Z",
"locked_by": "system-admin"
}
Database Record Lock Example
A client attempts to modify a record that is locked as part of a transaction:
Client Request:
PUT /api/orders/123 HTTP/1.1
Host: orders.example.com
Content-Type: application/json
Content-Length: 98
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{
"status": "shipped",
"tracking_number": "1Z999AA10123456784"
}
Server Response:
HTTP/1.1 423 Locked
Content-Type: application/json
Content-Length: 215
{
"error": "Locked",
"message": "This order is currently locked for processing",
"lock_reason": "Payment processing in progress",
"retry_after": 60,
"transaction_id": "txn-456789"
}
Summary
The 423 Locked
status code is an important mechanism for resource locking in collaborative environments, particularly in WebDAV systems but also in other applications that implement locking mechanisms. It helps prevent conflicts and data corruption by clearly indicating when a resource is locked and cannot be modified. By providing information about the lock, such as who holds it and when it might be released, servers can help clients understand when they might be able to retry their request successfully.