コード例 #1
0
        public static HttpRequestMessageWrapper Copy(this HttpRequestMessageWrapper request)
        {
            var result = new HttpRequestMessageWrapper {
                Method = request.Method
            };

            foreach (var header in request.Headers)
            {
                result.Headers.Add(header.Key, header.Value);
            }

            foreach (var property in request.Properties)
            {
                result.Properties.Add(property);
            }

            result.RequestUri = request.RequestUri;
            result.Version    = request.Version;
            var memoryStream = new MemoryStream();

            request.Content?.CopyToAsync(memoryStream);
            memoryStream.Position = 0;
            result.Content        = new StreamContent(memoryStream);
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Makes an asynchronous http GET request to the specified url.
        /// </summary>
        /// <param name="url">The url to send the request to.</param>
        /// <param name="prepareRequest">A callback that initializes the request with default values.</param>
        /// <param name="isLongRunning">Indicates whether the request is long running</param>
        /// <returns>A <see cref="T:Task{IResponse}"/>.</returns>
        public Task <IResponse> Get(string url, Action <IRequest> prepareRequest, bool isLongRunning)
        {
            if (prepareRequest == null)
            {
                throw new ArgumentNullException("prepareRequest");
            }
            var responseDisposer = new Disposer();
            var cts            = new CancellationTokenSource();
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(url));
            var request        = new HttpRequestMessageWrapper(requestMessage, () =>
            {
                cts.Cancel();
                responseDisposer.Dispose();
            });

            prepareRequest(request);
            HttpClient httpClient = GetHttpClient(isLongRunning);

            return(httpClient
                   .SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, cts.Token)
                   .ContinueWith(prev =>
            {
                var responseMessage = prev.Result;

                if (responseMessage.IsSuccessStatusCode)
                {
                    responseDisposer.Set(responseMessage);
                }
                else
                {
                    throw new HttpClientException(responseMessage);
                }
                return (IResponse) new HttpResponseMessageWrapper(responseMessage);
            }));
        }
コード例 #3
0
        public static DateTimeOffset?GetCreatedOn(this HttpRequestMessageWrapper wrapper)
        {
            var date      = wrapper.Headers[RequestDateHeader].FirstOrDefault();
            var createdOn = default(DateTimeOffset);

            DateTimeOffset.TryParse(date, out createdOn);
            return(createdOn);
        }
コード例 #4
0
 public HttpBatchContextWrapper(HttpContextBase httpContext, HttpRequestMessage httpRequest)
 {
     _httpContextBase    = httpContext;
     _items              = new Hashtable();
     _httpRequestWrapper = new HttpRequestMessageWrapper(
         httpContext.Request.ApplicationPath,
         httpRequest
         );
 }
コード例 #5
0
        private static HttpRequestMessage CopyRequest(HttpRequestMessageWrapper requestWrapper)
        {
            var request = new HttpRequestMessage(requestWrapper.Method, requestWrapper.RequestUri);

            request.Content = CopyContent(requestWrapper);
            CopyHeaders(requestWrapper, request.Headers);
            CopyProperties(requestWrapper, request);
            return(request);
        }
コード例 #6
0
        private static void CopyProperties(HttpRequestMessageWrapper source, HttpRequestMessage target)
        {
            var sourceProperties = source.Properties ?? Enumerable.Empty <KeyValuePair <string, object> >();

            foreach (KeyValuePair <string, object> property in sourceProperties)
            {
                target.Properties.Add(property.Key, property.Value);
            }
        }
        public GetRestaurantsDeliveryDataByPostCodeTests()
        {
            #region UnitTestPreparation

            _controllerRequester   = new HttpRequestMessageWrapper();
            _restarauntServiceMock = new RestaurantServiceMock();
            _client = new IntegrationTestServer(_restarauntServiceMock.Object).CreateClient();

            #endregion
        }
コード例 #8
0
        public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request)
        {
            if (request.Request.Method != HttpMethod.Get ||
                !request.Request.Headers.IfNoneMatch.Contains(ETagStore.GetOrCreateETag(request.CurrentCacheKey)))
            {
                return(null);
            }

            return(new HttpResponseMessageWrapper(
                       request.Request.CreateResponse(HttpStatusCode.NotModified)));
        }
コード例 #9
0
        /// <summary>
        /// Iterates over a Task list for faulted tasks and outputs the error messages
        /// </summary>
        /// <param name="tasks">List of tasks</param>
        /// <returns></returns>
        public static void OutputTaskErrorResults(List <Task> tasks)
        {
            Console.ForegroundColor = ConsoleColor.Red;

            tasks.Where(task => task.IsFaulted).ToList()
            .ForEach(task =>
            {
                Utils.WriteConsoleMessage($"\tTask Id: {task.Id}");
                foreach (CloudException ce in task.Exception.InnerExceptions)
                {
                    HttpRequestMessageWrapper request = ce.Request;
                    Utils.WriteConsoleMessage($"\t\tTask Exception Message: {ce.Message}");
                    Utils.WriteConsoleMessage($"\t\tTask Exception Request Content: {request.Content}");
                }
            });

            Console.ResetColor();
        }
コード例 #10
0
 public HttpRequestInfo(HttpRequestMessageWrapper request) : base(request)
 {
     Uri  = request.RequestUri;
     Verb = request.Method.ToString();
 }
コード例 #11
0
 public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request)
 {
     request.CurrentCacheKey.Append(Thread.CurrentPrincipal.Identity.Name);
     return(null);
 }
コード例 #12
0
ファイル: MaestroApi.cs プロジェクト: theaoqi/arcade-services
 public RestApiException(string message, HttpRequestMessageWrapper request, HttpResponseMessageWrapper response)
     : base(message)
 {
     Request  = request;
     Response = response;
 }
コード例 #13
0
ファイル: MaestroApi.cs プロジェクト: theaoqi/arcade-services
 public RestApiException(HttpRequestMessageWrapper request, HttpResponseMessageWrapper response)
     : this(FormatMessage(response), request, response)
 {
 }
コード例 #14
0
 public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request)
 {
     return(SynchronizedCacheManager.Instance.Get(request.CurrentCacheKey) as HttpResponseMessageWrapper);
 }
コード例 #15
0
 public static string GetSourceChannel(this HttpRequestMessageWrapper wrapper)
 {
     return(wrapper.Headers[RequestChannelHeader].FirstOrDefault());
 }
コード例 #16
0
 public static string GetRequestId(this HttpRequestMessageWrapper wrapper)
 {
     return(wrapper.Headers[RequestIdHeader].FirstOrDefault());
 }
コード例 #17
0
 public bool Process(HttpRequestMessageWrapper httpRequestMessageWrapper)
 {
     return(true);
 }
コード例 #18
0
 private void AssertMatrixEndpointCalled(HttpRequestMessageWrapper request)
 {
     request.GetEndpoint().ShouldBe($"GET {MatrixMovieUrl}");
     request.GetHeaderValue("Referer").ShouldBe(MovieProject.Logic.Constants.Website);
 }
コード例 #19
0
 public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request)
 {
     AppendVaryByParamsCacheKey(request.CurrentCacheKey, request.Request.RequestUri);
     return(null);
 }
コード例 #20
0
 public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request)
 {
     request.CurrentCacheKey = new CacheKey(cacheAttribute.DeclaringType);
     return(null);
 }
コード例 #21
0
 public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request)
 {
     SynchronizedCacheManager.Instance.Invalidate(request.CurrentCacheKey);
     return(null);
 }
コード例 #22
0
 public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request)
 {
     request.CurrentCacheKey.Append(request.Request.RequestUri.AbsolutePath);
     return(null);
 }