This topic has not yet been rated - Rate this topic

Specifying Conditional Headers for Blob Service Operations

Several Blob service operations support the use of conditional headers. You can specify conditional headers to carry out an operation only if a specified condition has been met.

The Blob service follows the HTTP/1.1 protocol specification for conditional headers.

This topic contains the following subtopics:

Supported Conditional Headers

Operations Supporting Conditional Headers

HTTP Response Codes for Operations Supporting Conditional Headers

Supported Conditional Headers

The supported conditional headers are described in the following table.

 

Conditional header Description

If-Modified-Since

A DateTime value. Specify this header to perform the operation only if the resource has been modified since the specified time.

If-Unmodified-Since

A DateTime value. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

If-Match

An ETag value. Specify this header to perform the operation only if the resource's ETag matches the value specified. For versions 2011-08-18 and newer, the ETag can be specified in quotes.

If-None-Match

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag does not match the value specified. For versions 2011-08-18 and newer, the ETag can be specified in quotes.

Specify the wildcard character (*) to perform the operation only if the resource does not exist, and fail the operation if it does exist.

When specifying conditional headers, keep in mind the following:

  • If a request specifies both the If-None-Match and If-Modified-Since headers, the request is evaluated based on the criteria specified in If-None-Match.

  • If a request specifies both the If-Match and If-Unmodified-Since headers, the request is evaluated based on the criteria specified in If-Match.

  • With the exception of the two combinations of conditional headers listed above, a request may specify only a single conditional header. Specifying more than one conditional header results in status code 400 (Bad Request).

  • If a response includes an ETag, verify the version of the request and response before processing the ETag. For example, version 2011-08-18 and newer return a quoted ETag, but older versions do not. Ensure that your application can process both ETag formats before they are evaluated.

  • RFC 2616 allows multiple ETag values in a single header, but requests to Windows Azure Blob storage can only include one ETag value. Specifying more than one ETag value results in status code 400 (Bad Request).

Operations Supporting Conditional Headers

The operations that support conditional headers are described in the following table. Methods in the Windows Azure .NET Libraries usually use the AccessCondition property to specify the conditions that must be met for the operation to be performed on the storage service.

 

.NET Method REST Operation Operation type Supported conditional headers

CloudBlob.UploadFromStream, UploadFile, UploadText, UploadByteArray, and others

Put Blob (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudBlob.DownloadToStream and others

Get Blob (REST API)

Read

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudBlob.FetchAttributes

Get Blob Properties (REST API)

Read

If-Modified-Since

If-Unmodified-Since

CloudBlob.SetProperties

Set Blob Properties (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudBlob.FetchAttributes

Get Blob Metadata (REST API)

Read

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudBlob.SetMetadata

Set Blob Metadata (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

BlobRequest.GetBlockList with AddConditional

Get Block List (REST API)

Read

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

BlobRequest.PutBlockList with BlobRequest.AddConditional

Put Block List (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudBlob.Delete, CloudBlob.DeleteIfExists

Delete Blob (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudBlob.CopyFromBlob

Copy Blob (REST API)

Read and Write

For conditions on the destination blob:

  • If-Modified-Since

  • If-Unmodified-Since

  • If-Match

  • If-None-Match

For conditions on the source blob:

  • x-ms-source-if-modified-since

  • x-ms-source-if-unmodified-since

  • x-ms-source-if-match

  • x-ms-source-if-none-match

CloudBlob.CreateSnapshot

Snapshot Blob (REST API)

Read

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

BlobRequest.PutPage with BlobRequest.AddConditional

Put Page (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudPageBlob.GetPageRanges

Get Page Ranges (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

BlobRequest.Lease with BlobRequest.AddConditional

Lease Blob (REST API)

Write

If-Modified-Since

If-Unmodified-Since

If-Match

If-None-Match

CloudBlobContainer.SetMetadata

Set Container Metadata (REST API)

Write

If-Modified-Since

CloudBlobContainer.Delete

Delete Container (REST API)

Write

If-Modified-Since

If-Unmodified-Since

HTTP Response Codes for Operations Supporting Conditional Headers

If the request includes a conditional header and the specified condition is not met by the resource being requested, the Blob service returns an HTTP response code. The response codes returned are in accordance with the HTTP/1.1 protocol specification (RFC 2616). Methods in the Windows Azure .NET Libraries convert these error response codes into a StorageClientException, and populate the StatusCode property with a value from the System.Net.HttpStatusCode enumeration. To see sample code that handles an exception caused by a conditional operation, see How to Conditionally Refresh a Local Copy of a Blob.

Read Operations

The following table indicates the response codes returned for an unmet condition for each conditional header when the operation is a read operation. Read operations use the verbs GET or HEAD.

 

Conditional header Response code if condition has not been met

If-Modified-Since

Not Modified (304)

If-Unmodified-Since

Precondition Failed (412)

If-Match

Precondition Failed (412)

If-None-Match

Not Modified (304)

Write Operations

The following table indicates the response codes returned for an unmet condition for each conditional header when the operation is a write operation. Write operations use the verbs PUT or DELETE.

 

Conditional header Response code if condition has not been met

If-Modified-Since

Precondition Failed (412)

If-Unmodified-Since

Precondition Failed (412)

If-Match

Precondition Failed (412)

If-None-Match

Precondition Failed (412)

Copy Operations

The following table indicates the response codes returned for an unmet condition for each conditional header when the operation is a copy operation. The Copy Blob (REST API) operation uses the verbs PUT.

 

Conditional header Response code if condition has not been met

If-Modified-Since

Precondition Failed (412)

If-Unmodified-Since

Precondition Failed (412)

If-Match

Precondition Failed (412)

If-None-Match

Precondition Failed (412)

x-ms-source-if-modified-since

Precondition Failed (412)

x-ms-source-if-unmodified-since

Precondition Failed (412)

x-ms-source-if-match

Precondition Failed (412)

x-ms-source-if-none-match

Precondition Failed (412)

See Also

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.
facebook page visit twitter rss feed newsletter