Example #1
0
        public static void SignRequest(HttpWebRequest request, FileContext context)
        {
            Assert.IsNotNull(request);
            Assert.IsNotNull(context);

            OperationContext opContext = new OperationContext();
            SharedKeyAuthenticationHandler handler = new SharedKeyAuthenticationHandler(
                SharedKeyCanonicalizer.Instance,
                context.Credentials,
                context.Account);
            handler.SignRequest(request, opContext);

            FileTestUtils.AuthorizationHeader(request, true, context.Account);
            FileTestUtils.DateHeader(request, true);
        }
        private static HttpWebRequest BlobGetRequest(KeyValuePair<long, int> blockOffsetAndLength, CloudBlockBlob blob)
        {
            StorageCredentials credentials = blob.ServiceClient.Credentials;
            var transformedUri = credentials.TransformUri(blob.Uri);

            // Prepare the HttpWebRequest to download data from the chunk.
            HttpWebRequest blobGetRequest = BlobHttpWebRequestFactory.Get(
                transformedUri,
                Timeout,
                snapshot: null,
                offset: blockOffsetAndLength.Key,
                count: blockOffsetAndLength.Value,
                rangeContentMD5: false,
                accessCondition: AccessCondition.GenerateEmptyCondition(),
                operationContext: new OperationContext());

            if (credentials.IsSharedKey)
            {
                IAuthenticationHandler authenticationHandler = new SharedKeyAuthenticationHandler(
                            SharedKeyCanonicalizer.Instance,
                            credentials,
                            credentials.AccountName);
                authenticationHandler.SignRequest(blobGetRequest, new OperationContext());
            }
            return blobGetRequest;
        }