@@ -90,6 +90,7 @@ public class InfluxDBClient : IInfluxDBClient
9090 private readonly HttpClient _httpClient ;
9191 private readonly FlightSqlClient _flightSqlClient ;
9292 private readonly RestClient _restClient ;
93+ private readonly GzipHandler _gzipHandler ;
9394
9495 /// <summary>
9596 /// This class provides an interface for interacting with an InfluxDB server,
@@ -107,6 +108,7 @@ public InfluxDBClient(string hostUrl, string? authToken = null, string? organiza
107108 Organization = organization ,
108109 Database = database ,
109110 AuthToken = authToken ,
111+ WriteOptions = WriteOptions . DefaultOptions
110112 } )
111113 {
112114 }
@@ -129,6 +131,7 @@ public InfluxDBClient(InfluxDBClientConfigs configs)
129131 _httpClient = CreateAndConfigureHttpClient ( _configs ) ;
130132 _flightSqlClient = new FlightSqlClient ( configs : _configs , httpClient : _httpClient ) ;
131133 _restClient = new RestClient ( configs : _configs , httpClient : _httpClient ) ;
134+ _gzipHandler = new GzipHandler ( configs . WriteOptions != null ? configs . WriteOptions . GzipThreshold : 0 ) ;
132135 }
133136
134137 /// <summary>
@@ -247,15 +250,16 @@ private async Task WriteData(IEnumerable<object> data, string? organization = nu
247250 throw new ObjectDisposedException ( nameof ( InfluxDBClient ) ) ;
248251 }
249252
250- var precisionNotNull = precision ?? _configs . WritePrecision ?? WritePrecision . Ns ;
253+ var precisionNotNull = precision ?? _configs . WritePrecision ;
251254 var sb = ToLineProtocolBody ( data , precisionNotNull ) ;
252255 if ( sb . Length == 0 )
253256 {
254257 Trace . WriteLine ( $ "The writes: { data } doesn't contains any Line Protocol, skipping") ;
255258 return ;
256259 }
257260
258- var content = new StringContent ( sb . ToString ( ) , Encoding . UTF8 , "text/plain" ) ;
261+ var body = sb . ToString ( ) ;
262+ var content = _gzipHandler . Process ( body ) ?? new StringContent ( body , Encoding . UTF8 , "text/plain" ) ;
259263 var queryParams = new Dictionary < string , string ? > ( )
260264 {
261265 {
@@ -314,19 +318,24 @@ private static StringBuilder ToLineProtocolBody(IEnumerable<object?> data, Write
314318
315319 internal static HttpClient CreateAndConfigureHttpClient ( InfluxDBClientConfigs configs )
316320 {
317- var handler = new HttpClientHandler
321+ var handler = new HttpClientHandler ( ) ;
322+ if ( handler . SupportsRedirectConfiguration )
318323 {
319- AllowAutoRedirect = configs . AllowHttpRedirects
320- } ;
321-
324+ handler . AllowAutoRedirect = configs . AllowHttpRedirects ;
325+ }
326+ if ( handler . SupportsAutomaticDecompression )
327+ {
328+ handler . AutomaticDecompression = System . Net . DecompressionMethods . GZip | System . Net . DecompressionMethods . Deflate ;
329+ }
322330 if ( configs . DisableServerCertificateValidation )
323331 {
324332 handler . ServerCertificateCustomValidationCallback = ( _ , _ , _ , _ ) => true ;
325333 }
326334
327- var client = new HttpClient ( handler ) ;
328-
329- client . Timeout = configs . Timeout ;
335+ var client = new HttpClient ( handler )
336+ {
337+ Timeout = configs . Timeout
338+ } ;
330339 client . DefaultRequestHeaders . UserAgent . ParseAdd ( $ "influxdb3-csharp/{ AssemblyHelper . GetVersion ( ) } ") ;
331340 if ( ! string . IsNullOrEmpty ( configs . AuthToken ) )
332341 {
0 commit comments