Skip to content

Commit

Permalink
Fix tests and BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Nov 14, 2024
1 parent f8e54a0 commit 8eda127
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
33 changes: 29 additions & 4 deletions src/Elastic.Transport/Components/Pipeline/RequestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public RequestData(ITransportConfiguration global, IRequestConfiguration? local
ProxyPassword = global.ProxyPassword;
DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection;
UserAgent = global.UserAgent;
ResponseBuilders = local?.ResponseBuilders ?? global.ResponseBuilders;
ProductResponseBuilders = global.ProductRegistration.ResponseBuilders;

KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
KeepAliveTime = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);
RunAs = local?.RunAs ?? global.RunAs;
Expand Down Expand Up @@ -89,8 +86,36 @@ public RequestData(ITransportConfiguration global, IRequestConfiguration? local
Headers ??= [];
Headers.Add(OpaqueIdHeader, local.OpaqueId);
}
}

// If there are builders set at the transport level and on the request config, we combine them,
// prioritising the request config response builders as most specific.
if (local is not null && local.ResponseBuilders.Count > 0 && global.ResponseBuilders.Count > 0)
{
var builders = new IResponseBuilder[local.ResponseBuilders.Count + global.ResponseBuilders.Count];

var counter = 0;
foreach (var builder in local.ResponseBuilders)
{
builders[counter++] = builder;
}
foreach (var builder in global.ResponseBuilders)
{
builders[counter++] = builder;
}

ResponseBuilders = builders;
}
else if (local is not null && local.ResponseBuilders.Count > 0)
{
ResponseBuilders = local.ResponseBuilders;
}
else
{
ResponseBuilders = global.ResponseBuilders;
}

ProductResponseBuilders = global.ProductRegistration.ResponseBuilders;
}

/// <inheritdoc cref="ITransportConfiguration.MemoryStreamFactory"/>
public MemoryStreamFactory MemoryStreamFactory { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public RequestConfiguration(IRequestConfiguration config)
ResponseHeadersToParse = (config.ResponseHeadersToParse is null) ? null : new HeadersList(config.ResponseHeadersToParse);
ParseAllHeaders = config.ParseAllHeaders;
RequestMetaData = config.RequestMetaData;
ResponseBuilders = config.ResponseBuilders;
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

using Elastic.Transport.Extensions;
Expand Down Expand Up @@ -49,6 +50,7 @@ public RequestConfigurationDescriptor(IRequestConfiguration? config)
_responseHeadersToParse = (config.ResponseHeadersToParse is null) ? null : new HeadersList(config.ResponseHeadersToParse);
_parseAllHeaders = config.ParseAllHeaders;
_requestMetaData = config.RequestMetaData;
_responseBuilders = [.. config.ResponseBuilders];
}

private string? _accept;
Expand Down Expand Up @@ -336,5 +338,5 @@ public RequestConfigurationDescriptor ResponseBuilder(IResponseBuilder responseB

RequestMetaData? IRequestConfiguration.RequestMetaData => _requestMetaData;

IReadOnlyCollection<IResponseBuilder> IRequestConfiguration.ResponseBuilders => _responseBuilders;
IReadOnlyCollection<IResponseBuilder> IRequestConfiguration.ResponseBuilders => _responseBuilders ?? [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void SameDefaults()
public void CopiesAllProperties()
{
var autoFaker = new AutoFaker<RequestConfiguration>();
autoFaker.RuleFor(x => x.ClientCertificates, f => new X509CertificateCollection());
autoFaker.RuleFor(x => x.ClientCertificates, f => []);

var config = autoFaker.Generate();
config.Accept.Should().NotBeEmpty();
Expand Down

0 comments on commit 8eda127

Please sign in to comment.