Skip to content

Commit

Permalink
Update Elastic.Transport
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Nov 14, 2024
1 parent 824a6b8 commit 1274938
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public ElasticsearchClientProductRegistration(Type markerType) : base(markerType

public override string ServiceIdentifier => "esv";

public override string DefaultMimeType => null; // Prevent base 'ElasticsearchProductRegistration' from sending the compatibility header
public override string? DefaultContentType => null; // Prevent base 'ElasticsearchProductRegistration' from sending the compatibility header

public override MetaHeaderProvider MetaHeaderProvider => _metaHeaderProvider;

/// <summary>
/// Elastic.Clients.Elasticsearch handles 404 in its <see cref="ElasticsearchResponse.IsValidResponse" />, we do not want the low level client throwing
/// exceptions
/// when <see cref="ITransportConfiguration.ThrowExceptions" /> is enabled for 404's. The client is in charge of
/// when <see cref="IRequestConfiguration.ThrowExceptions" /> is enabled for 404's. The client is in charge of
/// composing paths
/// so a 404 never signals a wrong URL but a missing entity.
/// </summary>
Expand Down Expand Up @@ -77,7 +77,7 @@ public class ApiVersionMetaHeaderProducer : MetaHeaderProducer

public override string HeaderName => "Elastic-Api-Version";

public override string ProduceHeaderValue(RequestData requestData) => _apiVersion;
public override string ProduceHeaderValue(RequestData requestData, bool isAsync) => _apiVersion;

public ApiVersionMetaHeaderProducer(VersionInfo version)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Nullable>annotations</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Transport" Version="0.4.26" />
<PackageReference Include="Elastic.Transport" Version="0.5.2" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Tests" Key="$(ExposedPublicKey)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ElasticsearchClientProductRegistration(Type markerType) : base(markerType
/// <summary>
/// Elastic.Clients.Elasticsearch handles 404 in its <see cref="ElasticsearchResponse.IsValidResponse" />, we do not want the low level client throwing
/// exceptions
/// when <see cref="ITransportConfiguration.ThrowExceptions" /> is enabled for 404's. The client is in charge of
/// when <see cref="IRequestConfiguration.ThrowExceptions" /> is enabled for 404's. The client is in charge of
/// composing paths
/// so a 404 never signals a wrong URL but a missing entity.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Nullable>annotations</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Transport" Version="0.4.26" />
<PackageReference Include="Elastic.Transport" Version="0.5.2" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Tests" Key="$(ExposedPublicKey)" />
Expand Down
20 changes: 14 additions & 6 deletions src/Elastic.Clients.Elasticsearch/_Shared/Api/BulkRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ namespace Elastic.Clients.Elasticsearch;

public partial class BulkRequest : IStreamSerializable
{
internal Request Self => this;
private static readonly IRequestConfiguration RequestConfigSingleton = new RequestConfiguration
{
Accept = "application/json",
ContentType = "application/x-ndjson"
};

public BulkOperationsCollection Operations { get; set; }
internal Request Self => this;

internal override string ContentType => "application/x-ndjson";
protected internal override IRequestConfiguration RequestConfig => RequestConfigSingleton;

internal override string Accept => "application/json";
public BulkOperationsCollection Operations { get; set; }

public void Serialize(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting = SerializationFormatting.None)
{
Expand Down Expand Up @@ -87,9 +91,13 @@ public async Task SerializeAsync(Stream stream, IElasticsearchClientSettings set

public sealed partial class BulkRequestDescriptor : IStreamSerializable
{
internal override string ContentType => "application/x-ndjson";
private static readonly IRequestConfiguration RequestConfigSingleton = new RequestConfiguration
{
Accept = "application/json",
ContentType = "application/x-ndjson"
};

internal override string Accept => "application/json";
protected internal override IRequestConfiguration RequestConfig => RequestConfigSingleton;

private readonly BulkOperationsCollection _operations = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
#if ELASTICSEARCH_SERVERLESS
namespace Elastic.Clients.Elasticsearch.Serverless.Esql;
#else

namespace Elastic.Clients.Elasticsearch.Esql;
#endif

internal sealed class EsqlResponseBuilder : CustomResponseBuilder
internal sealed class EsqlResponseBuilder : TypedResponseBuilder<EsqlQueryResponse>
{
public override object DeserializeResponse(Serializer serializer, ApiCallDetails response, Stream stream)
protected override EsqlQueryResponse? Build(ApiCallDetails apiCallDetails, RequestData requestData,
Stream responseStream,
string contentType, long contentLength)
{
var bytes = stream switch
var bytes = responseStream switch
{
MemoryStream ms => ms.ToArray(),
_ => BytesFromStream(stream)
_ => BytesFromStream(responseStream)
};

return new EsqlQueryResponse { Data = bytes };
Expand All @@ -37,13 +38,14 @@ static byte[] BytesFromStream(Stream stream)
}
}

public override async Task<object> DeserializeResponseAsync(Serializer serializer, ApiCallDetails response, Stream stream,
CancellationToken ctx = new CancellationToken())
protected override async Task<EsqlQueryResponse?> BuildAsync(ApiCallDetails apiCallDetails, RequestData requestData,
Stream responseStream,
string contentType, long contentLength, CancellationToken cancellationToken = default)
{
var bytes = stream switch
var bytes = responseStream switch
{
MemoryStream ms => ms.ToArray(),
_ => await BytesFromStreamAsync(stream, ctx).ConfigureAwait(false)
_ => await BytesFromStreamAsync(responseStream, cancellationToken).ConfigureAwait(false)
};

return new EsqlQueryResponse { Data = bytes };
Expand All @@ -62,10 +64,3 @@ static async Task<byte[]> BytesFromStreamAsync(Stream stream, CancellationToken
}
}
}

public sealed partial class EsqlQueryRequestParameters
{
private static readonly EsqlResponseBuilder ResponseBuilder = new();

public EsqlQueryRequestParameters() => CustomResponseBuilder = ResponseBuilder;
}
Loading

0 comments on commit 1274938

Please sign in to comment.