protected async Task <HttpResponseMessage> ExecuteRequestAsync( HttpRequestMessage requestMessage, HttpCompletionOption httpCompletionOption, int redirectionCount = 0, CancellationToken token = default(CancellationToken)) { if (redirectionCount >= MaxAutomaticRedirections) { throw new HttpRequestException("Exceeded maximum number of allowed redirects."); } var requestExecutor = ShareFileClient.AsyncRequestExecutor ?? RequestExecutorFactory.GetAsyncRequestExecutor(); var responseMessage = await requestExecutor.SendAsync(HttpClient, requestMessage, httpCompletionOption, token).ConfigureAwait(false); var redirect = responseMessage.GetSecureRedirect(); if (redirect != null) { return(await ExecuteRequestAsync(requestMessage.Clone(redirect), httpCompletionOption, ++redirectionCount, token).ConfigureAwait(false)); } ProcessCookiesForRuntime(responseMessage); return(responseMessage); }
protected void ConfigureItemResponse(string root = null) { HttpRequestMessage requestMessage = null; A.CallTo(() => RequestExecutorFactory.GetAsyncRequestExecutor() .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .That.Matches( message => root == null || message.RequestUri.ToString().Contains("root=" + root)), A <HttpCompletionOption> .Ignored, A <CancellationToken> .Ignored)) .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options, CancellationToken token) => { requestMessage = message; }) .ReturnsLazily(() => GenerateItemResponse(requestMessage)); A.CallTo(() => RequestExecutorFactory.GetSyncRequestExecutor() .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .That.Matches( message => root == null || message.RequestUri.ToString().Contains("root=" + root)), A <HttpCompletionOption> .Ignored)) .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options) => { requestMessage = message; }) .ReturnsLazily(() => GenerateItemResponse(requestMessage)); }
protected async Task <HttpResponseMessage> ExecuteRequestAsync(HttpRequestMessage requestMessage, HttpCompletionOption httpCompletionOption, CancellationToken?token = null) { HttpResponseMessage responseMessage; var requestExecutor = RequestExecutorFactory.GetAsyncRequestExecutor(); responseMessage = await requestExecutor.SendAsync(HttpClient, requestMessage, httpCompletionOption, token ?? CancellationToken.None); ProcessCookiesForRuntime(responseMessage); return(responseMessage); }
protected void ConfigureZoneUnavailableResponse() { A.CallTo(() => RequestExecutorFactory.GetAsyncRequestExecutor() .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored, A <CancellationToken> .Ignored)) .Returns(GenerateRedirectionUnavailableResponse()); A.CallTo(() => RequestExecutorFactory.GetSyncRequestExecutor() .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored)) .Returns(GenerateRedirectionUnavailableResponse()); }
protected void ConfigureDomainChangedResponse(string root = null) { A.CallTo(() => RequestExecutorFactory.GetAsyncRequestExecutor() .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored, A <CancellationToken> .Ignored)) .Returns(GenerateRedirectionResponse(root)); A.CallTo(() => RequestExecutorFactory.GetSyncRequestExecutor() .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored)) .Returns(GenerateRedirectionResponse(root)); }
protected void ConfigureAsyncOperationScheduled() { A.CallTo(() => RequestExecutorFactory.GetAsyncRequestExecutor() .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored, A <CancellationToken> .Ignored)) .Returns(GenerateAsyncOperationScheduled()); A.CallTo(() => RequestExecutorFactory.GetSyncRequestExecutor() .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored)) .Returns(GenerateAsyncOperationScheduled()); }
protected void ConfigureStreamResponse(string responseContent) { A.CallTo(() => RequestExecutorFactory.GetAsyncRequestExecutor() .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored, A <CancellationToken> .Ignored)) .Returns(this.GenerateStreamResponse(responseContent)); A.CallTo(() => RequestExecutorFactory.GetSyncRequestExecutor() .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored)) .Returns(this.GenerateStreamResponse(responseContent)); }
protected void ConfigureNotFound() { A.CallTo(() => RequestExecutorFactory.GetAsyncRequestExecutor() .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored, A <CancellationToken> .Ignored)) .Returns(GenerateODataRequestException(HttpStatusCode.NotFound, "Items: NotFound")); A.CallTo(() => RequestExecutorFactory.GetSyncRequestExecutor() .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored)) .Returns(GenerateODataRequestException(HttpStatusCode.NotFound, "Items: NotFound")); }
internal void RegisterRequestProviders() { RequestProviderFactory = new RequestProviderFactory(); RegisterSyncRequestProvider(() => new SyncRequestProvider(this)); if (RequestExecutorFactory.GetSyncRequestExecutor() == null) { RequestExecutorFactory.RegisterSyncRequestProvider(new SyncRequestExecutor()); } #if ASYNC RegisterAsyncRequestProvider(() => new AsyncRequestProvider(this)); if (RequestExecutorFactory.GetAsyncRequestExecutor() == null) { RequestExecutorFactory.RegisterAsyncRequestProvider(new AsyncRequestExecutor()); } #endif }
protected void ConfigureUnauthorizedResponse() { HttpRequestMessage requestMessage = null; A.CallTo(() => RequestExecutorFactory.GetAsyncRequestExecutor() .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored, A <CancellationToken> .Ignored)) .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options, CancellationToken token) => { requestMessage = message; }) .ReturnsLazily(() => GenerateUnauthorizedResponse(requestMessage)); A.CallTo(() => RequestExecutorFactory.GetSyncRequestExecutor() .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored)) .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options) => { requestMessage = message; }) .ReturnsLazily(() => GenerateUnauthorizedResponse(requestMessage)); }