private void UploadUrlContent(IHttpRequestInfo urlContentUploadInfo) { using (var httpClient = GetHttpClient()) { using (var request = new HttpRequestMessage(new HttpMethod(urlContentUploadInfo.Method), urlContentUploadInfo.URL)) { request.SetHeaders(urlContentUploadInfo.Headers); httpClient.CheckedSendAsync(request).Wait(); } } }
protected override void OnInit(EventArgs e) { base.OnInit(e); _requestInfo = new HttpRequestInfo(Request); }
/// <summary> /// Attempts to parse the supplied HttpContent instance and constructs an IHttpResponseInfo response object. /// If parsing fails on a successful response, an exception is thrown. /// </summary> /// <typeparam name="TResponse">The expected Type of the converted HttpContent.</typeparam> /// <param name="httpRequestInfo">The IHttpRequestInfo instance describing the request.</param> /// <param name="statusCode">The status code associated with the HTTP response.</param> /// <param name="content">The HttpContent object which should be parsed.</param> /// <returns>A Task returning the expected response object Type.</returns> private async Task <IHttpResponseInfo <TResponse> > ParseHttpContentAndConstructResponse <TResponse>(IHttpRequestInfo httpRequestInfo, HttpStatusCode statusCode, IResponseContentConverter <TResponse> responseContentConverter, HttpContent content) where TResponse : class { var is2xxCode = (int)statusCode >= 200 && (int)statusCode <= 299; // If this isn't a success code, we don't try to handle the response content and so return an empty error response object. if (!is2xxCode) { return(new HttpResponseInfo <TResponse>(statusCode, httpRequestInfo)); } // Otherwise, we try to parse the content. Failures to parse in 2xx cases here are considered fatal so we let any exceptions bubble up. var responseContent = await responseContentConverter.ConvertFrom(content); return(new HttpResponseInfo <TResponse>(statusCode, httpRequestInfo, responseContent)); }
/// <summary> /// Creates a new HttpResponseInfo instance. /// </summary> /// <param name="statusCode">The status code associated with the response.</param> /// <param name="requestInfo">Information describing the request which gave rise to this response.</param> internal HttpResponseInfo(HttpStatusCode statusCode, IHttpRequestInfo requestInfo) { StatusCode = statusCode; RequestInfo = requestInfo ?? throw new ArgumentNullException(nameof(requestInfo)); }
public static string ResolveSkinsFullCdnPath(IHttpRequestInfo requestInfo) { return ResolveResourceFullCdnPath(SkinsCdnUrlAppSetting, requestInfo); }
private static string ResolveResourceFullCdnPath(string resourceBaseCdnUrl, IHttpRequestInfo httpRequestInfo) { string compressionPartOfUrl = httpRequestInfo.SupportsGzip ? CompressedPath : UncompressedPath; return String.Format("{0}/{1}", resourceBaseCdnUrl, compressionPartOfUrl); }