RateProviderHttpClientFactory Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.dll
- Package
- Bodu.Financial.ExchangeRates 1.0.0
Creates and configures the HttpClient a web-backed exchange-rate provider owns when the caller does not supply one, applying the HTTP contract (user agent and request timeout) the remote endpoint requires.
public static class RateProviderHttpClientFactory
- Inheritance
-
RateProviderHttpClientFactory
- Inherited Members
Remarks
A provider that builds its own client owns the HTTP contract with the endpoint: it presents a recognizable
User-Agent (several feeds - Yahoo Finance in particular - answer requests without one with
429 Too Many Requests) and applies the configured request timeout. When the caller supplies a client instead,
provisioning it correctly is the caller's responsibility, so this factory is not involved.
The returned client is owned by the provider that requested it and is disposed when that provider is disposed.
Fields
DefaultMaxResponseContentBufferSize
The default cap, in bytes, applied to MaxResponseContentBufferSize for a provider-owned client (64 MiB).
public const long DefaultMaxResponseContentBufferSize = 67108864
Field Value
Remarks
The exchange-rate feeds these clients address return small payloads (a CSV, XML, or JSON document), so a finite ceiling well above any legitimate response prevents a compromised or man-in-the-middle endpoint from driving unbounded memory use, while never affecting a well-formed response.
Methods
Create(string?, TimeSpan, long)
Creates a new HttpClient configured with the supplied user agent, request timeout, and response-content buffer cap.
public static HttpClient Create(string? userAgent, TimeSpan httpTimeout, long maxResponseContentBufferSize = 67108864)
Parameters
userAgentstringThe
User-Agentheader applied to every request. A null, empty, or white-space value suppresses the header.httpTimeoutTimeSpanThe request timeout applied to the client. Values not greater than zero are ignored.
maxResponseContentBufferSizelongThe maximum number of bytes to buffer when reading a response. Values not greater than zero are ignored, leaving the framework default; the default caps the client at DefaultMaxResponseContentBufferSize.
Returns
- HttpClient
A new, configured HttpClient.
Remarks
The timeout is applied to Timeout directly because a provider-owned client has no resilience handler enforcing a per-attempt timeout; a dependency-injection registration that adds its own resilience pipeline supplies its client to the provider instead and does not use this factory. The buffer cap bounds the memory a single response can consume, so an oversized body fails rather than exhausting memory.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |