From dev-return-58854-archive-asf-public=cust-asf.ponee.io@thrift.apache.org Thu Jun 25 10:54:04 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9C243180181 for ; Thu, 25 Jun 2020 12:54:03 +0200 (CEST) Received: (qmail 92818 invoked by uid 500); 25 Jun 2020 10:54:02 -0000 Mailing-List: contact dev-help@thrift.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@thrift.apache.org Delivered-To: mailing list dev@thrift.apache.org Received: (qmail 92789 invoked by uid 99); 25 Jun 2020 10:54:02 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Jun 2020 10:54:02 +0000 Received: from jira-he-de.apache.org (static.172.67.40.188.clients.your-server.de [188.40.67.172]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 05EA842259 for ; Thu, 25 Jun 2020 10:54:00 +0000 (UTC) Received: from jira-he-de.apache.org (localhost.localdomain [127.0.0.1]) by jira-he-de.apache.org (ASF Mail Server at jira-he-de.apache.org) with ESMTP id 2E86278017B for ; Thu, 25 Jun 2020 10:54:00 +0000 (UTC) Date: Thu, 25 Jun 2020 10:54:00 +0000 (UTC) From: "Lewis Jackson (Jira)" To: dev@thrift.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (THRIFT-5239) THttpTransport should support passing in an HttpClient MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Lewis Jackson created THRIFT-5239: ------------------------------------- Summary: THttpTransport should support passing in an HttpClient Key: THRIFT-5239 URL: https://issues.apache.org/jira/browse/THRIFT-5239 Project: Thrift Issue Type: Bug Components: netstd - Library Reporter: Lewis Jackson This issue is very similar to the Java one documented here: https://issues.apache.org/jira/browse/THRIFT-970 .NET Core supports using an _[IHttpClientFactory|https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1]_ 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|https://github.com/apache/thrift/blob/283410126ccb3ac4990045e07cccb5df11ee2a16/lib/netstd/Thrift/Transport/Client/THttpTransport.cs#L141]. 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: {code:c#} var httpClientFactory = serviceProvider.GetService(); var httpClient = httpClientFactory.CreateClient("thrift"); var transport = new THttpTransport(httpClient); {code} After registering their own named _IHttpClientFactory_ in the _ServiceCollection_: {code:c#} var certificates = GetCertificates(); services.AddHttpClient("thrift", c => { c.BaseAddress = new Uri("https://foo.bar/Service.thrift"); 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 }; handler.ClientCertificates.AddRange(certificates); return handler; }); {code} Rather than relying on users to properly configure request headers and decompression methods themselves, an extension method to _ServiceCollection_ could be defined: {code:c#} services.AddThriftHttpClient("thrift", uri, customRequestHeaders, userAgent, certificates); {code} 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 (v8.3.4#803005)