HTTP 423 Locked (WebDAV)

Overview

The HTTP 423 Locked status code is used to indicate that the source or destination resource of a method is locked, preventing the requested operation. This status is often associated with WebDAV (Web Distributed Authoring and Versioning) scenarios, where resources can be explicitly locked to prevent concurrent editing.

Purpose

The HTTP 423 response is used to inform the client that the requested operation cannot be completed because the resource is currently locked.

Usage

Client Behavior:

  1. Send Request: The client sends an HTTP request to perform an operation on a locked resource.
  2. Receive Response: The client receives the 423 Locked status code, indicating that the resource is currently locked.

Server Behavior:

  1. Detect Lock: The server detects that the requested operation is incompatible with the lock status of the resource.
  2. Send Response: The server responds with a 423 Locked status, indicating the resource’s lock status.

Scenarios

  • Concurrent Editing: When resources, especially in collaborative environments, are explicitly locked to prevent concurrent edits.
  • WebDAV Operations: WebDAV clients may encounter a 423 status when attempting operations on locked resources.

Sequence Diagram

Illustrating the process for an HTTP 423 response:

sequenceDiagram
    participant Client
    participant Server as Web Server

    Note over Client: Client attempts an operation on a locked resource
    Client->>Server: PUT /locked-resource HTTP/1.1
    Note over Server: Server detects the lock status
    Server->>Client: HTTP/1.1 423 Locked

Curl Request and Response Example

Attempting an operation on a locked resource using Curl:

curl -i -X PUT http://example.com/locked-resource
# Expected response: HTTP/1.1 423 Locked
# Additional details: ...

PHP cURL Request and Response Example

PHP script using cURL to handle a 423 Locked response:

<?php
$ch = curl_init('http://example.com/locked-resource');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 423) {
    echo "Locked. Additional details: " . $response;
}
curl_close($ch);
?>

Python Request and Response Example

Python script to send a request to perform an operation on a locked resource and handle a 423 Locked response:

import requests
response = requests.put('http://example.com/locked-resource')
if response.status_code == 423:
    print("Locked. Additional details:", response.text)

Apache Configuration for HTTP 423 Locked

Configuring Apache to handle locked resource scenarios and return a 423 Locked response:

<VirtualHost *:80>
    ServerName example.com
    <Location "/locked-resource">
        # Configure resource locking logic
        <IfModule mod_dav.c>
            DavLockDB "/path/to/lockdb"
        </IfModule>
        <LimitExcept GET HEAD>
            Order Deny,Allow
            Deny from all
            AllowOverride None
            Dav On
            Require user admin
        </LimitExcept>
        # Return 423 Locked on locked resources
        ErrorDocument 423 "HTTP/1.1 423 Locked"
        Header always append Retry-After "3600" # Set appropriate retry time
    </Location>
</VirtualHost>

NGINX Configuration for HTTP 423 Locked

Setting up NGINX to handle locked resource scenarios and respond with a 423 Locked status:

server {
    listen 80;
    server_name example.com;
    location /locked-resource {
        # Configure resource locking logic
        # (NGINX does not have native WebDAV support, consider third-party modules)
        
        # Return 423 Locked on locked resources
        return 423 "HTTP/1.1 423 Locked";
        add_header Retry-After "3600"; # Set appropriate retry time
    }
}

HTTP 422 Unprocessable Entity (WebDAV) HTTP 424 Failed Dependency (WebDAV)


 

Free Weekly

Newsletter

Join my weekly newsletter for the latest in tech! You'll get neat coding tricks, trend updates, career advice, SaaS reviews, crypto, bitcoin, and financial tips. All straight to your inbox, designed to keep you ahead.