Skip to content

Commit 2a6978d

Browse files
committed
Fix #1856 respect DisableDirectStreaming setting on error responses
1 parent 129e899 commit 2a6978d

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/Elasticsearch.Net/Transport/Pipeline/ResponseBuilder.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ private ElasticsearchResponse<TReturn> Initialize(int? statusCode, Exception exc
5454
}
5555

5656
private void SetBody(ElasticsearchResponse<TReturn> response, Stream stream)
57-
{
57+
{
58+
byte[] bytes = null;
59+
if (NeedsToEagerReadStream())
60+
{
61+
var inMemoryStream = this._requestData.MemoryStreamFactory.Create();
62+
stream.CopyTo(inMemoryStream, BufferSize);
63+
bytes = this.SwapStreams(ref stream, ref inMemoryStream);
64+
}
65+
5866
if (response.Success)
5967
{
60-
byte[] bytes = null;
61-
if (NeedsToEagerReadStream())
62-
{
63-
var inMemoryStream = this._requestData.MemoryStreamFactory.Create();
64-
stream.CopyTo(inMemoryStream, BufferSize);
65-
bytes = this.SwapStreams(ref stream, ref inMemoryStream);
66-
}
67-
6868
if (!SetSpecialTypes(stream, response, bytes))
6969
{
7070
if (this._requestData.CustomConverter != null) response.Body = this._requestData.CustomConverter(response, stream) as TReturn;
@@ -76,21 +76,23 @@ private void SetBody(ElasticsearchResponse<TReturn> response, Stream stream)
7676
ServerError serverError;
7777
if (ServerError.TryCreate(stream, out serverError))
7878
response.ServerError = serverError;
79+
if (this._requestData.ConnectionSettings.DisableDirectStreaming)
80+
response.ResponseBodyInBytes = bytes;
7981
}
8082
}
8183

8284
private async Task SetBodyAsync(ElasticsearchResponse<TReturn> response, Stream stream)
83-
{
85+
{
86+
byte[] bytes = null;
87+
if (NeedsToEagerReadStream())
88+
{
89+
var inMemoryStream = this._requestData.MemoryStreamFactory.Create();
90+
await stream.CopyToAsync(inMemoryStream, BufferSize, this._requestData.CancellationToken).ConfigureAwait(false);
91+
bytes = this.SwapStreams(ref stream, ref inMemoryStream);
92+
}
93+
8494
if (response.Success)
8595
{
86-
byte[] bytes = null;
87-
if (NeedsToEagerReadStream())
88-
{
89-
var inMemoryStream = this._requestData.MemoryStreamFactory.Create();
90-
await stream.CopyToAsync(inMemoryStream, BufferSize, this._requestData.CancellationToken).ConfigureAwait(false);
91-
bytes = this.SwapStreams(ref stream, ref inMemoryStream);
92-
}
93-
9496
if (!SetSpecialTypes(stream, response, bytes))
9597
{
9698
if (this._requestData.CustomConverter != null) response.Body = this._requestData.CustomConverter(response, stream) as TReturn;
@@ -100,6 +102,8 @@ private async Task SetBodyAsync(ElasticsearchResponse<TReturn> response, Stream
100102
else if (response.HttpStatusCode != null)
101103
{
102104
response.ServerError = await ServerError.TryCreateAsync(stream, this._requestData.CancellationToken).ConfigureAwait(false);
105+
if (this._requestData.ConnectionSettings.DisableDirectStreaming)
106+
response.ResponseBodyInBytes = bytes;
103107
}
104108
}
105109

src/Tests/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: i
2+
mode: u
33
# the elasticsearch version that should be started
44
elasticsearch_version: 2.0.1
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running

0 commit comments

Comments
 (0)