The 207 Multi-Status
HTTP status code is a WebDAV-specific status code that provides multiple status responses for different parts of a request. WebDAV (Web Distributed Authoring and Versioning) is an extension of the HTTP protocol that allows clients to perform remote web content authoring operations. This status code is used to indicate that a request has been partially successful, and some parts of the request may have failed.
When to Use 207 Multi-Status
The 207 Multi-Status
status code is used when a single request involves multiple operations, and the server needs to return the status of each operation individually. This is particularly useful in WebDAV applications where a single request can affect multiple resources.
Common scenarios where a 207 Multi-Status
response might be used include:
- Batch operations: When a client sends a request to perform multiple operations, such as creating, updating, or deleting multiple resources in a single request.
- Transactional operations: When a client sends a request to perform an operation that affects multiple resources, and the server needs to return the status of each affected resource.
Structure of a 207 Multi-Status Response
A 207 Multi-Status
response contains an XML payload that provides detailed information about the status of each operation performed as part of the request. The XML payload follows the structure defined in the WebDAV specification.
Here is a high-level overview of the XML structure:
<multistatus xmlns="DAV:">
<response>
<href>...</href>
<status>...</status>
<!-- Additional elements specific to the operation -->
</response>
<!-- Additional <response> elements for each affected resource -->
</multistatus>
The <multistatus>
element is the root element of the XML payload, and it contains one or more <response>
elements. Each <response>
element represents the status of an individual operation and includes:
<href>
: The URL of the affected resource.<status>
: The HTTP status code and reason phrase for the operation.- Additional elements specific to the operation, such as
<propstat>
for PROPFIND requests.
Example: 207 Multi-Status Response
Consider a scenario where a client sends a PROPFIND request to retrieve properties of multiple resources. The server successfully retrieves properties for some resources but encounters errors for others. In this case, the server can return a 207 Multi-Status
response to provide the status of each operation.
Request:
PROPFIND /resources HTTP/1.1
Host: example.com
Content-Type: application/xml
Depth: 1
Response:
HTTP/1.1 207 Multi-Status
Content-Type: application/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:">
<response>
<href>/resources/resource1</href>
<propstat>
<prop>
<displayname>Resource 1</displayname>
<getcontenttype>text/plain</getcontenttype>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/resources/resource2</href>
<status>HTTP/1.1 404 Not Found</status>
</response>
</multistatus>
In this example, the server returns a 207 Multi-Status
response with two <response>
elements. The first <response>
element indicates that the properties for /resources/resource1
were successfully retrieved with a 200 OK
status. The second <response>
element indicates that the properties for /resources/resource2
could not be retrieved due to a 404 Not Found
error.
Summary
The 207 Multi-Status
HTTP status code is a WebDAV-specific status code used to provide multiple status responses for different parts of a request. It is commonly used in scenarios involving batch or transactional operations that affect multiple resources. A 207 Multi-Status
response contains an XML payload with detailed information about the status of each operation, allowing clients to determine the success or failure of individual operations within a single request.