thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lewis Jackson (Jira)" <>
Subject [jira] [Created] (THRIFT-5239) THttpTransport should support passing in an HttpClient
Date Thu, 25 Jun 2020 10:54:00 GMT
Lewis Jackson created THRIFT-5239:

             Summary: THttpTransport should support passing in an HttpClient
                 Key: THRIFT-5239
             Project: Thrift
          Issue Type: Bug
          Components: netstd - Library
            Reporter: Lewis Jackson

This issue is very similar to the Java one documented here:

.NET Core supports using an _[IHttpClientFactory|]_
to request instances of HttpClient. This factory will pool clients to avoid exhausting sockets
in the OS. Microsoft currently do not recommend creating a new _HttpClient_ per request, consumers
currently have to find a way to pool Thrift clients in order to conform to this practice.

The line which instantiates a new _HttpClient_ can be found [here|].

This proposal would require a new constructor which allowed an instance of _HttpClient_ to
be passed in. The consumer could use this constructor like this:

var httpClientFactory = serviceProvider.GetService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("thrift");
var transport = new THttpTransport(httpClient);

After registering their own named _IHttpClientFactory_ in the _ServiceCollection_:

var certificates = GetCertificates();

services.AddHttpClient("thrift", c =>
    c.BaseAddress = new Uri("");

    c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-thrift"));
    c.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
    c.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));

    c.DefaultRequestHeaders.Add("CUSTOM-HEADER", "HEADER-VALUE");
  .ConfigurePrimaryHttpMessageHandler(() =>
      var handler = new HttpClientHandler()
          AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip
      return handler;

Rather than relying on users to properly configure request headers and decompression methods
themselves, an extension method to _ServiceCollection_ could be defined:

services.AddThriftHttpClient("thrift", uri, customRequestHeaders, userAgent, certificates);

This would more closely match the current constructor of _THttpTransport_.

We've forked the _THttpTransport _ file to support this behaviour for internal purposes, so
I could put up a sample PR if requested.

This message was sent by Atlassian Jira

View raw message