/// <summary> /// Generic function to redirect a put request for properties of a blob /// </summary> public static async Task <HandlerResult> BasicBlobAsync(IHttpRequestWrapper requestWrapper, string container, string blob, bool servePrimaryOnly, bool operationCanReplicateBlob) { return(await WebOperationRunner.DoHandlerAsync("BlobHandler.BasicBlobAsync", async() => { var namespaceBlob = await NamespaceHandler.FetchNamespaceBlobAsync(container, blob); if (!await namespaceBlob.ExistsAsync()) { return new HandlerResult { StatusCode = HttpStatusCode.NotFound, }; } string accountName = namespaceBlob.SelectDataAccount(servePrimaryOnly); if (operationCanReplicateBlob) { if (namespaceBlob.IsReplicated || BlobReplicationHandler.ShouldReplicateBlob(requestWrapper.Headers, container, blob)) { accountName = namespaceBlob.PrimaryAccountName; await BlobReplicationHandler.EnqueueBlobReplicationAsync(namespaceBlob, false); } } Uri redirect = ControllerOperations.GetRedirectUri(HttpContextFactory.Current.Request, DashConfiguration.GetDataAccountByAccountName(accountName), namespaceBlob.Container, namespaceBlob.BlobName, false); return HandlerResult.Redirect(requestWrapper, redirect); })); }
public void RedirectionSignatureTest() { var request = new MockHttpRequestWrapper("GET", "http://localhost/container/test%20encoded", null) { AuthenticationScheme = "SharedKey", AuthenticationKey = DashConfiguration.AccountKey, }; var result = HandlerResult.Redirect(request, "http://dataaccount.blob.core.windows.net/container/test%20encoded"); result.Headers = new ResponseHeaders(new[] { new KeyValuePair <string, string>("x-ms-date", "Wed, 01 Apr 2015 01:26:43 GMT"), }); Assert.AreEqual(result.SignedLocation, "SharedKey dashstorage1:iU0kJCrvLR7rdIS/HXO0T04gTu09enDo25/3WtrjESI="); // Secondary key request = new MockHttpRequestWrapper("GET", "http://localhost/container/test%20encoded", null) { AuthenticationScheme = "SharedKeyLite", AuthenticationKey = DashConfiguration.SecondaryAccountKey, }; result = HandlerResult.Redirect(request, "http://dataaccount.blob.core.windows.net/container/test%20encoded"); result.Headers = new ResponseHeaders(new[] { new KeyValuePair <string, string>("x-ms-date", "Wed, 01 Apr 2015 01:26:43 GMT"), }); Assert.AreEqual(result.SignedLocation, "SharedKeyLite dashstorage1:o3XAz28naFjcSxCbqoZL394S/zLY2+nYk7v8KbdnlSI="); }
public static async Task <HandlerResult> PutBlobAsync(IHttpRequestWrapper requestWrapper, string container, string blob, bool operationCanReplicateBlob) { return(await WebOperationRunner.DoHandlerAsync("BlobHandler.PutBlobAsync", async() => { var namespaceBlob = await NamespaceHandler.CreateNamespaceBlobAsync(container, blob); if (operationCanReplicateBlob) { if (BlobReplicationHandler.ShouldReplicateBlob(requestWrapper.Headers, container, blob)) { await BlobReplicationHandler.EnqueueBlobReplicationAsync(namespaceBlob, false); } } Uri redirect = ControllerOperations.GetRedirectUri(HttpContextFactory.Current.Request, DashConfiguration.GetDataAccountByAccountName(namespaceBlob.PrimaryAccountName), container, blob, false); return HandlerResult.Redirect(requestWrapper, redirect); })); }