Health checks and networking
Health.Check
Pineapple.Health.Check provides quick yes/no probes for dependencies — useful in startup checks, CLI tools, and test fixtures.
using Pineapple.Health;
bool dbPortOpen = Check.IsAlive("sql.contoso.internal", 1433); // TCP connect
bool siteUp = Check.IsUrlAvailable("https://contoso.com/health", timeoutInMs: 5_000); // HTTP 200
bool running = Check.IsRunning("dotnet"); // process name contains "dotnet"
bool apiUp = new Uri("https://api.contoso.com/ping").IsUrlAvailable(2_000);
All probes return false instead of throwing when the target is unreachable. For ASP.NET Core readiness and liveness endpoints, use these inside a IHealthCheck.
BrotliCompressionHandler
A DelegatingHandler that decompresses Content-Encoding: br responses with System.IO.Compression.BrotliStream, for IHttpClientFactory pipelines.
using Pineapple.Networking;
builder.Services
.AddHttpClient("catalog", c => c.BaseAddress = new Uri("https://catalog.contoso.com"))
.AddBrotliCompression(builder.Services);
Remember to send Accept-Encoding: br on requests. If you control the primary handler, HttpClientHandler.AutomaticDecompression = DecompressionMethods.Brotli achieves the same thing without a delegating handler.
Questions about health checks and networking
How do I check if a TCP port is open in C#?
Call Pineapple.Health.Check.IsAlive(host, port). It attempts a TCP connection and returns true if it succeeds.
How do I enable Brotli decompression for HttpClient?
The simplest option is new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }. If you build HttpClient pipelines with IHttpClientFactory and DelegatingHandlers, add Pineapple’s handler with services.AddHttpClient("api").AddBrotliCompression(services).