$ show dotnet/yarp
YARP (Yet Another Reverse Proxy) is a high-performance, extensible reverse proxy toolkit for .NET, built on ASP.NET Core. It provides a library and samples for creating custom proxy servers with features including request forwarding, load balancing (random, round-robin, least-requests, power-of-two-choices), active and passive health checks, session affinity (cookie, hash, ARR, custom header), request/response transforms, and telemetry consumption. The architecture is middleware-based, with a pipeline that includes routing, load balancing, session affinity, health checks, and delegation (Http.sys). Configuration is driven by immutable records and supports dynamic reload via change tokens. YARP also includes a Kubernetes Ingress Controller module that watches Ingress, Service, Endpoint, and Secret resources to dynamically configure the proxy. The codebase demonstrates strong engineering practices: extensive unit and functional tests, pluggable policy interfaces, efficient stream copying with telemetry, and a transform builder pattern for declarative request/response modifications. It is actively maintained by Microsoft and used in production scenarios.
The LLM identified 4 files worth highlighting for reuse:
Parses TLS ClientHello and ServerHello frames to extract SNI, ALPN, supported versions, and cipher suites without requiring full certificate decryption. This is a self-contained utility that can be extracted for any TLS-aware proxy or network tool needing SNI-based routing or protocol negotiation inspection. It demonstrates careful byte-level parsing with error handling for malformed frames.
Efficiently copies data between streams with integrated telemetry (timing, bytes transferred) and support for cancellation. Uses ArrayPool for buffer reuse and reports metrics via ForwarderTelemetry. This component is reusable in any .NET application requiring high-performance stream copying with observability, such as file uploads or data transfer services.
A pooled CancellationTokenSource that combines cancellation from a request abort, an activity timeout, and an external token. It avoids allocation overhead by reusing instances (with a max queue size). This pattern is reusable for any .NET service needing coordinated cancellation with timeouts, especially in high-throughput proxy or middleware scenarios.
A token bucket rate limiter ported from Go's rate package, used by the Kubernetes controller to throttle reconciliation. It supports bursts, reservations, and cancellation. This is a standalone, well-tested implementation that can be extracted for any .NET application requiring rate limiting, such as API gateways or background job processors.