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
19 changes: 19 additions & 0 deletions src/OpenAC.Net.DFe.Core.Tests/Http/DFeHttpTransportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ public async Task CompatibilityOptionsPreserveCookiesWithoutSharingThemWithDefau
await Assert.That(requests[2].Contains("Cookie:", StringComparison.OrdinalIgnoreCase)).IsFalse();
}

[Test]
public async Task CookiesStayInsideTheTenantPool()
{
using var server = new LocalServer(_ => 200);
var config = new HttpTestConfiguration();
foreach (var tenant in new[] { "empresa-a", "empresa-b", "empresa-a" })
{
using var request = new HttpRequestMessage(HttpMethod.Get, server.Url);
using var response = await DFeHttpTransport.Instance.SendAsync(request,
new(config.WebServices) { TenantId = tenant, UseCookies = true });
}

var requests = server.Requests.ToArray();
await Assert.That(requests.Length).IsEqualTo(3);
await Assert.That(requests[0].Contains("Cookie:", StringComparison.OrdinalIgnoreCase)).IsFalse();
await Assert.That(requests[1].Contains("Cookie:", StringComparison.OrdinalIgnoreCase)).IsFalse();
await Assert.That(requests[2]).Contains("Cookie: tenant=anterior");
}

[Test]
public async Task PerAttemptTimeoutDoesNotLimitRetryDelayOrWholeOperation()
{
Expand Down
4 changes: 3 additions & 1 deletion src/OpenAC.Net.DFe.Core/Http/DFeHttpTransportBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Polly.Timeout;

namespace OpenAC.Net.DFe.Core.Http;

Expand Down Expand Up @@ -61,7 +62,8 @@ public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, DFe
if (attempt == attempts || !IsTransient(response.StatusCode)) return response;
response.Dispose();
}
catch (HttpRequestException) when (attempt < attempts && !token.IsCancellationRequested)
catch (Exception exception) when (exception is HttpRequestException or TimeoutRejectedException
&& attempt < attempts && !token.IsCancellationRequested)
{
// Apenas GET, HEAD, OPTIONS e TRACE podem repetir falhas de transporte.
}
Expand Down
5 changes: 4 additions & 1 deletion src/OpenAC.Net.DFe.Core/Http/DFeHttpTransportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ public DFeHttpTransportOptions(DFeWebserviceConfigBase configuration, X509Certif
/// <summary>Margem mínima de validade do certificado da operação.</summary>
public TimeSpan MargemValidadeCertificado { get; set; } = TimeSpan.FromMinutes(5);

/// <summary>Partição opcional de clientes e políticas por tenant.</summary>
public string? TenantId { get; set; }

/// <summary>Identidade do pool, incluindo as políticas capturadas para a operação.</summary>
public string GetPoolKey(Uri endpoint) =>
$"{Certificate?.Thumbprint}|{(int)Protocols}|{Proxy}|{ValidateServerCertificate}|{UseCookies}|{AllowAutoRedirect}|{(int)AutomaticDecompression}|{endpoint.GetLeftPart(UriPartial.Authority)}|{Timeout.Ticks}|{TimeoutTentativa.Ticks}|{TimeoutPerAttempt}|{CircuitBreakerHabilitado}|{TempoVidaHandler.Ticks}|{TempoVidaConexaoPool.Ticks}";
$"{TenantId?.Length ?? 0}:{TenantId}|{Certificate?.Thumbprint}|{(int)Protocols}|{Proxy}|{ValidateServerCertificate}|{UseCookies}|{AllowAutoRedirect}|{(int)AutomaticDecompression}|{endpoint.GetLeftPart(UriPartial.Authority)}|{Timeout.Ticks}|{TimeoutTentativa.Ticks}|{TimeoutPerAttempt}|{CircuitBreakerHabilitado}|{TempoVidaHandler.Ticks}|{TempoVidaConexaoPool.Ticks}";

/// <summary>Certificado mTLS emprestado pelo chamador durante o envio.</summary>
public X509Certificate2? Certificate { get; }
Expand Down
8 changes: 4 additions & 4 deletions src/OpenAC.Net.DFe.Core/OpenAC.Net.DFe.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageProjectUrl>https://openac.net.br/</PackageProjectUrl>
<PackageVersion>1.8.1</PackageVersion>
<AssemblyVersion>1.8.1</AssemblyVersion>
<FileVersion>1.8.1</FileVersion>
<Version>1.8.1</Version>
<PackageVersion>1.8.2</PackageVersion>
<AssemblyVersion>1.8.2</AssemblyVersion>
<FileVersion>1.8.2</FileVersion>
<Version>1.8.2</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
Expand Down