diff --git a/src/Elasticsearch.Net/Connection/Configuration/ConnectionConfiguration.cs b/src/Elasticsearch.Net/Connection/Configuration/ConnectionConfiguration.cs index eb109323c67..77b9d1c7186 100644 --- a/src/Elasticsearch.Net/Connection/Configuration/ConnectionConfiguration.cs +++ b/src/Elasticsearch.Net/Connection/Configuration/ConnectionConfiguration.cs @@ -106,6 +106,9 @@ public class ConnectionConfiguration : IConnectionConfigurationValues, IHideO private TimeSpan? _sniffLifeSpan; TimeSpan? IConnectionConfigurationValues.SniffInformationLifeSpan { get{ return _sniffLifeSpan; } } + private bool _compressionEnabled; + bool IConnectionConfigurationValues.EnableCompressedResponses { get{ return _compressionEnabled; } } + private bool _traceEnabled; bool IConnectionConfigurationValues.TraceEnabled { get{ return _traceEnabled; } } @@ -159,6 +162,16 @@ public T SniffLifeSpan(TimeSpan sniffTimeSpan) return (T)this; } + /// + /// Enable compressed responses from elasticsearch (NOTE that that nodes need to be configured to allow this) + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html + /// + public T EnableCompressedResponses(bool enabled = true) + { + this._compressionEnabled = enabled; + return (T) this; + } + /// /// Enable Trace signals to the IConnection that it should put debug information on the Trace. /// diff --git a/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfiguration.cs b/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfiguration.cs index 78278e19ee6..99edb5ba8ac 100644 --- a/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfiguration.cs +++ b/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfiguration.cs @@ -13,6 +13,12 @@ public interface IConnectionConfiguration : IHideObjectMembers where T : IConnectionConfiguration { + /// + /// Enable compressed responses from elasticsearch (NOTE that that nodes need to be configured to allow this) + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html + /// + T EnableCompressedResponses(bool enabled = true); + /// /// Enable Trace signals to the IConnection that it should put debug information on the Trace. diff --git a/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfigurationValues.cs b/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfigurationValues.cs index c1ff0a0c3b7..29bebf644d9 100644 --- a/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfigurationValues.cs +++ b/src/Elasticsearch.Net/Connection/Configuration/IConnectionConfigurationValues.cs @@ -16,6 +16,7 @@ public interface IConnectionConfigurationValues int? MaxDeadTimeout { get; } int? MaxRetries { get; } bool DisablePings { get; } + bool EnableCompressedResponses { get; } string ProxyAddress { get; } string ProxyUsername { get; } diff --git a/src/Elasticsearch.Net/Connection/HttpConnection.cs b/src/Elasticsearch.Net/Connection/HttpConnection.cs index 941855bc0ee..1d6fbe935db 100644 --- a/src/Elasticsearch.Net/Connection/HttpConnection.cs +++ b/src/Elasticsearch.Net/Connection/HttpConnection.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Linq; using System.Net; using System.Runtime.InteropServices; @@ -170,9 +171,13 @@ protected virtual HttpWebRequest CreateWebRequest(Uri uri, string method, byte[] //var url = this._CreateUriString(path); var myReq = (HttpWebRequest)WebRequest.Create(uri); - myReq.Accept = "application/json"; myReq.ContentType = "application/json"; + if (this.ConnectionSettings.EnableCompressedResponses) + { + myReq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + myReq.Headers.Add("Accept-Encoding", "gzip,deflate"); + } if (requestSpecificConfig != null && !string.IsNullOrWhiteSpace(requestSpecificConfig.ContentType)) { myReq.Accept = requestSpecificConfig.ContentType; diff --git a/src/Tests/Nest.Tests.Integration/ElasticsearchConfiguration.cs b/src/Tests/Nest.Tests.Integration/ElasticsearchConfiguration.cs index 75d965f0fd0..c985068c52d 100644 --- a/src/Tests/Nest.Tests.Integration/ElasticsearchConfiguration.cs +++ b/src/Tests/Nest.Tests.Integration/ElasticsearchConfiguration.cs @@ -39,7 +39,7 @@ public static ConnectionSettings Settings(int? port = null, Uri hostOverride = n .ExposeRawResponse(); } - public static readonly ElasticClient Client = new ElasticClient(Settings()); + public static readonly ElasticClient Client = new ElasticClient(Settings().EnableCompressedResponses()); public static readonly ElasticClient ClientNoRawResponse = new ElasticClient(Settings().ExposeRawResponse(false)); public static readonly ElasticClient ClientThatTrows = new ElasticClient(Settings().ThrowOnElasticsearchServerExceptions()); public static readonly ElasticClient ThriftClient = new ElasticClient(Settings(9500), new ThriftConnection(Settings(9500))); diff --git a/src/Tests/Nest.Tests.Integration/Reproduce/Reproduce325Tests.cs b/src/Tests/Nest.Tests.Integration/Reproduce/Reproduce325Tests.cs index a8a41962802..2945cc44779 100644 --- a/src/Tests/Nest.Tests.Integration/Reproduce/Reproduce325Tests.cs +++ b/src/Tests/Nest.Tests.Integration/Reproduce/Reproduce325Tests.cs @@ -44,6 +44,7 @@ public void FluentMappingReturnsResults() }) .AddMapping(m => MapTechnicalProduct(m, indexName))); + var index = this._client.GetIndexSettings(i=>i.Index(indexName)); }