Skip to content

fix #693 can now instruct the HTTP client to accept gzip, deflated respo... #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public class ConnectionConfiguration<T> : 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; } }

Expand Down Expand Up @@ -159,6 +162,16 @@ public T SniffLifeSpan(TimeSpan sniffTimeSpan)
return (T)this;
}

/// <summary>
/// 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
/// </summary>
public T EnableCompressedResponses(bool enabled = true)
{
this._compressionEnabled = enabled;
return (T) this;
}

/// <summary>
/// Enable Trace signals to the IConnection that it should put debug information on the Trace.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public interface IConnectionConfiguration<out T> : IHideObjectMembers
where T : IConnectionConfiguration<T>
{

/// <summary>
/// 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
/// </summary>
T EnableCompressedResponses(bool enabled = true);


/// <summary>
/// Enable Trace signals to the IConnection that it should put debug information on the Trace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
7 changes: 6 additions & 1 deletion src/Elasticsearch.Net/Connection/HttpConnection.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void FluentMappingReturnsResults()
})
.AddMapping<TechnicalProduct>(m => MapTechnicalProduct(m, indexName)));

var index = this._client.GetIndexSettings(i=>i.Index(indexName));
}


Expand Down