This is an automated email from the ASF dual-hosted git repository. jensg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/thrift.git
commit 27d8387c49a49fcf193893f834e9766ae0b051c1 Author: Jens Geyer <[email protected]> AuthorDate: Sat May 4 12:11:52 2019 +0200 THRIFT-4860 Allow changing "User-Agent" Client: netstd Patch: Jens Geyer --- lib/netstd/Thrift/Transport/Client/THttpTransport.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/netstd/Thrift/Transport/Client/THttpTransport.cs b/lib/netstd/Thrift/Transport/Client/THttpTransport.cs index 0dd5493..627c93d 100644 --- a/lib/netstd/Thrift/Transport/Client/THttpTransport.cs +++ b/lib/netstd/Thrift/Transport/Client/THttpTransport.cs @@ -1,4 +1,4 @@ -// Licensed to the Apache Software Foundation(ASF) under one +// Licensed to the Apache Software Foundation(ASF) under one // or more contributor license agreements.See the NOTICE file // distributed with this work for additional information // regarding copyright ownership.The ASF licenses this file @@ -41,23 +41,29 @@ namespace Thrift.Transport.Client private bool _isDisposed; private MemoryStream _outputStream = new MemoryStream(); - public THttpTransport(Uri u, IDictionary<string, string> customHeaders = null) - : this(u, Enumerable.Empty<X509Certificate>(), customHeaders) + public THttpTransport(Uri u, IDictionary<string, string> customHeaders = null, string userAgent = null) + : this(u, Enumerable.Empty<X509Certificate>(), customHeaders, userAgent) { } public THttpTransport(Uri u, IEnumerable<X509Certificate> certificates, - IDictionary<string, string> customHeaders) + IDictionary<string, string> customHeaders, string userAgent = null) { _uri = u; _certificates = (certificates ?? Enumerable.Empty<X509Certificate>()).ToArray(); CustomHeaders = customHeaders; + if (!string.IsNullOrEmpty(userAgent)) + UserAgent = userAgent; + // due to current bug with performance of Dispose in netcore https://github.com/dotnet/corefx/issues/8809 // this can be switched to default way (create client->use->dispose per flush) later _httpClient = CreateClient(); } + // According to RFC 2616 section 3.8, the "User-Agent" header may not carry a version number + public readonly string UserAgent = "Thrift netstd THttpClient"; + public IDictionary<string, string> CustomHeaders { get; } public int ConnectTimeout @@ -149,7 +155,7 @@ namespace Thrift.Transport.Client } httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-thrift")); - httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("THttpTransport", "1.0.0")); + httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd(UserAgent); if (CustomHeaders != null) { @@ -223,4 +229,4 @@ namespace Thrift.Transport.Client _isDisposed = true; } } -} \ No newline at end of file +}
