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
34 changes: 31 additions & 3 deletions src/ModularPipelines/Context/ICertificates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,41 @@

namespace ModularPipelines.Context;

/// <summary>
/// Provides functionality for retrieving X.509 certificates from the certificate store.
/// </summary>
public interface ICertificates
{
public X509Certificate2? GetCertificateBySubject(StoreLocation storeLocation, string subject);
/// <summary>
/// Gets a certificate by its subject name.
/// </summary>
/// <param name="storeLocation">The store location to search.</param>
/// <param name="subject">The subject name to search for.</param>
/// <returns>The matching certificate, or null if not found.</returns>
X509Certificate2? GetCertificateBySubject(StoreLocation storeLocation, string subject);

public X509Certificate2? GetCertificateByThumbprint(StoreLocation storeLocation, string thumbprint);
/// <summary>
/// Gets a certificate by its thumbprint.
/// </summary>
/// <param name="storeLocation">The store location to search.</param>
/// <param name="thumbprint">The thumbprint to search for.</param>
/// <returns>The matching certificate, or null if not found.</returns>
X509Certificate2? GetCertificateByThumbprint(StoreLocation storeLocation, string thumbprint);

public X509Certificate2? GetCertificateBySerialNumber(StoreLocation storeLocation, string serialNumber);
/// <summary>
/// Gets a certificate by its serial number.
/// </summary>
/// <param name="storeLocation">The store location to search.</param>
/// <param name="serialNumber">The serial number to search for.</param>
/// <returns>The matching certificate, or null if not found.</returns>
X509Certificate2? GetCertificateBySerialNumber(StoreLocation storeLocation, string serialNumber);

/// <summary>
/// Gets a certificate using a custom find type and value.
/// </summary>
/// <param name="storeLocation">The store location to search.</param>
/// <param name="findType">The type of search to perform.</param>
/// <param name="findValue">The value to search for.</param>
/// <returns>The matching certificate, or null if not found.</returns>
X509Certificate2? GetCertificateBy(StoreLocation storeLocation, X509FindType findType, string findValue);
}
5 changes: 5 additions & 0 deletions src/ModularPipelines/Http/ResponseLoggingHttpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

// Buffer the response content so it can be read multiple times.
// Without this, reading the body for logging consumes the stream,
// making it unreadable by subsequent code. See issue #1610.
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);

Copilot AI Jan 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response.Content property could potentially be null, which would cause a NullReferenceException when calling LoadIntoBufferAsync(). Consider adding a null check before buffering the content.

Suggested change
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
if (response.Content is not null)
{
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
}

Copilot uses AI. Check for mistakes.

Copilot AI Jan 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix for issue #1610 (buffering response content before logging) lacks test coverage. Consider adding a test that verifies the response body can still be read after logging, which would prevent regression of this bug. The test should make an HTTP request, enable response logging, and then verify the response body is still readable.

Copilot uses AI. Check for mistakes.

await _httpLogger.PrintResponse(response, _logger).ConfigureAwait(false);

return response;
Expand Down
Loading