GeoRedundantReadPolicy
This policy is used if the SecondaryUri property is passed in on the clientOptions. It allows for storage
accounts configured with RA-GRS to retry GET or HEAD requests against the secondary storage Uri.
using Azure.Core;
using System;
namespace Azure.Storage
{
internal class GeoRedundantReadPolicy
{
private readonly string _secondaryStorageHost;
public GeoRedundantReadPolicy(Uri secondaryStorageUri)
: this()
{
if (secondaryStorageUri == (Uri)null)
throw Errors.ArgumentNull("secondaryStorageUri");
_secondaryStorageHost = secondaryStorageUri.Host;
}
public override void OnSendingRequest(HttpMessage message)
{
if (!(message.get_Request().get_Method() != RequestMethod.get_Get()) || !(message.get_Request().get_Method() != RequestMethod.get_Head())) {
object obj = default(object);
string text = message.TryGetProperty("AlternateHostKey", ref obj) ? (obj as string) : null;
object obj2 = default(object);
if (text == null)
message.SetProperty("AlternateHostKey", (object)_secondaryStorageHost);
else if (!message.TryGetProperty("ResourceNotReplicated", ref obj2) || !(bool)obj2) {
string host = message.get_Request().get_Uri().get_Host();
if (message.get_HasResponse() && message.get_Response().get_Status() == 404 && host == _secondaryStorageHost)
message.SetProperty("ResourceNotReplicated", (object)true);
message.get_Request().get_Uri().set_Host(text);
message.SetProperty("AlternateHostKey", (object)host);
}
}
}
}
}