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); }
/// <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); })); }
public static DateTimeOffset?GetCreatedOn(this HttpRequestMessageWrapper wrapper) { var date = wrapper.Headers[RequestDateHeader].FirstOrDefault(); var createdOn = default(DateTimeOffset); DateTimeOffset.TryParse(date, out createdOn); return(createdOn); }
public HttpBatchContextWrapper(HttpContextBase httpContext, HttpRequestMessage httpRequest) { _httpContextBase = httpContext; _items = new Hashtable(); _httpRequestWrapper = new HttpRequestMessageWrapper( httpContext.Request.ApplicationPath, httpRequest ); }
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); }
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 }
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))); }
/// <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(); }
public HttpRequestInfo(HttpRequestMessageWrapper request) : base(request) { Uri = request.RequestUri; Verb = request.Method.ToString(); }
public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request) { request.CurrentCacheKey.Append(Thread.CurrentPrincipal.Identity.Name); return(null); }
public RestApiException(string message, HttpRequestMessageWrapper request, HttpResponseMessageWrapper response) : base(message) { Request = request; Response = response; }
public RestApiException(HttpRequestMessageWrapper request, HttpResponseMessageWrapper response) : this(FormatMessage(response), request, response) { }
public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request) { return(SynchronizedCacheManager.Instance.Get(request.CurrentCacheKey) as HttpResponseMessageWrapper); }
public static string GetSourceChannel(this HttpRequestMessageWrapper wrapper) { return(wrapper.Headers[RequestChannelHeader].FirstOrDefault()); }
public static string GetRequestId(this HttpRequestMessageWrapper wrapper) { return(wrapper.Headers[RequestIdHeader].FirstOrDefault()); }
public bool Process(HttpRequestMessageWrapper httpRequestMessageWrapper) { return(true); }
private void AssertMatrixEndpointCalled(HttpRequestMessageWrapper request) { request.GetEndpoint().ShouldBe($"GET {MatrixMovieUrl}"); request.GetHeaderValue("Referer").ShouldBe(MovieProject.Logic.Constants.Website); }
public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request) { AppendVaryByParamsCacheKey(request.CurrentCacheKey, request.Request.RequestUri); return(null); }
public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request) { request.CurrentCacheKey = new CacheKey(cacheAttribute.DeclaringType); return(null); }
public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request) { SynchronizedCacheManager.Instance.Invalidate(request.CurrentCacheKey); return(null); }
public HttpResponseMessageWrapper Invoke(HttpRequestMessageWrapper request) { request.CurrentCacheKey.Append(request.Request.RequestUri.AbsolutePath); return(null); }