Skip to content
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 @@ -87,6 +87,10 @@ public class ConnectionConfiguration<T> : IConnectionConfigurationValues, IHideO

private bool _usePrettyResponses;
bool IConnectionConfigurationValues.UsesPrettyResponses { get{ return _usePrettyResponses; } }

private bool _usePrettyRequests;
bool IConnectionConfigurationValues.UsesPrettyRequests { get{ return _usePrettyRequests; } }

#if DEBUG
private bool _keepRawResponse = true;
#else
Expand Down Expand Up @@ -153,6 +157,7 @@ public ConnectionConfiguration(IConnectionPool connectionPool)
this._connectionStatusHandler = this.ConnectionStatusDefaultHandler;
this._maximumAsyncConnections = 0;
this._connectionPool = connectionPool;
this._usePrettyRequests = true;
}

public ConnectionConfiguration(Uri uri = null)
Expand Down Expand Up @@ -357,6 +362,26 @@ public T SetProxy(Uri proxyAdress, string username, string password)
return (T) this;
}

/// <summary>
/// Sets <see cref="UsePrettyRequests"/> and <see cref="UsePrettyResponses"/> in one go.
/// Whether we want to send and recieve formatted json
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
public T PrettyJson(bool b = true)
{
return this.UsePrettyRequests(b).UsePrettyResponses(b);
}

/// <summary>
/// Defaults to true, wether to send formatted json to elasticsearch or not
/// </summary>
public T UsePrettyRequests(bool b = true)
{
this._usePrettyRequests = b;
return (T) this;
}

/// <summary>
/// Append ?pretty=true to requests, this helps to debug send and received json.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public interface IConnectionConfigurationValues
/// </summary>
bool MetricsEnabled { get; }

/// <summary>
/// Forces the client to pretty format the requests send to elasticsearch
/// defaults to true;
/// </summary>
bool UsesPrettyRequests { get; }

/// <summary>
/// Forces elasticsearch to send pretty json responses over the wire
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ protected byte[] PostData(object data)
if (ss != null) return (string.Join("\n", ss) + "\n").Utf8Bytes();

var so = data as IEnumerable<object>;
if (so == null) return this._serializer.Serialize(data);
var indent = this._settings.UsesPrettyRequests
? SerializationFormatting.Indented
: SerializationFormatting.None;
if (so == null) return this._serializer.Serialize(data, indent);
var joined = string.Join("\n", so
.Select(soo => this._serializer.Serialize(soo, SerializationFormatting.None).Utf8String())) + "\n";
return joined.Utf8Bytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public T Deserialize<T>(Stream stream)
return SimpleJson.DeserializeObject<T>(buffer.Utf8String());
}
}

public Task<T> DeserializeAsync<T>(Stream stream)
{
var tcs = new TaskCompletionSource<T>();
Expand Down