Skip to content
This repository was archived by the owner on Apr 10, 2018. It is now read-only.
This repository was archived by the owner on Apr 10, 2018. It is now read-only.

Use ModernHttpClient Instead of DefaultHttpClientFactory #34

@adamfisher

Description

@adamfisher

Is there an easy way to replace the HttpClientFactory on the client so it uses ModernHttpClient's NativeMessageHandler?

This is my initial stab at integrating it but I didn't see a way to set the _proxyProperty from the DefaultHttpClientFactory the same way it did.

/// <summary>
    /// An HTTP Client Factory that uses the high-performance ModernHttpClient's NativeMessageHandler to process requests.
    /// </summary>
    public class ModernHttpClientFactory : DefaultHttpClientFactory
    {
        #region Methods

        /// <summary>
        /// Create the message handler.
        /// </summary>
        /// <param name="client">The REST client that wants to create the HTTP client</param>
        /// <param name="request">The REST request for which the HTTP client is created</param>
        /// <returns>
        /// A new HttpMessageHandler object
        /// </returns>
        protected override HttpMessageHandler CreateMessageHandler(IRestClient client, IRestRequest request)
        {
            var proxy = GetProxy(client);
            var cookies = GetCookies(client, request);
            var credentials = client.Credentials;
            var httpClientHandler = new NativeMessageHandler();

            if (httpClientHandler.SupportsProxy && proxy != null)
            {
                httpClientHandler.UseProxy = true;
                httpClientHandler.Proxy = new RequestProxyWrapper(proxy); ;
            }

            if (cookies != null)
            {
                httpClientHandler.UseCookies = true;
                httpClientHandler.CookieContainer = cookies;
            }

            if (credentials != null)
            {
                httpClientHandler.Credentials = credentials;
            }

            return httpClientHandler;
        }

        #endregion
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions