예제 #1
0
        private void SetBody(ElasticsearchResponse <TReturn> response, Stream stream)
        {
            if (response.Success)
            {
                byte[] bytes = null;
                if (NeedsToEagerReadStream())
                {
                    var inMemoryStream = this._requestData.MemoryStreamFactory.Create();
                    stream.CopyTo(inMemoryStream, BufferSize);
                    bytes = this.SwapStreams(ref stream, ref inMemoryStream);
                }

                if (!SetSpecialTypes(stream, response, bytes))
                {
                    if (this._requestData.CustomConverter != null)
                    {
                        response.Body = this._requestData.CustomConverter(response, stream) as TReturn;
                    }
                    else
                    {
                        response.Body = this._requestData.ConnectionSettings.Serializer.Deserialize <TReturn>(stream);
                    }
                }
            }
            else if (response.HttpStatusCode != null)
            {
                ServerError serverError;
                if (ServerError.TryCreate(stream, out serverError))
                {
                    response.ServerError = serverError;
                }
            }
        }
 private void ReadServerError(ElasticsearchResponse <TReturn> response, Stream stream, byte[] bytes)
 {
     if (ServerError.TryCreate(stream, out var serverError))
     {
         response.ServerError = serverError;
     }
     if (_disableDirectStreaming)
     {
         response.ResponseBodyInBytes = bytes;
     }
 }