Class PluginHttpClientBuilder
Creates an HttpClient based on the customizable settings.
public class PluginHttpClientBuilder
- Inheritance
-
PluginHttpClientBuilder
- Inherited Members
Fields
ExDnsResolverWriteBufferLen
public const int ExDnsResolverWriteBufferLen = 512
Field Value
ExHttpTimeoutDefault
public const double ExHttpTimeoutDefault = 90
Field Value
ExMaxConnectionsDefault
public const int ExMaxConnectionsDefault = 32
Field Value
Properties
DecompressionMethod
public DecompressionMethods DecompressionMethod { get; set; }
Property Value
ExternalProxy
public static WebProxy? ExternalProxy { get; }
Property Value
HttpAuthHeader
public string? HttpAuthHeader { get; set; }
Property Value
HttpBaseUri
public Uri? HttpBaseUri { get; set; }
Property Value
HttpHeaders
public Dictionary<string, string?> HttpHeaders { get; set; }
Property Value
HttpProtocolVersion
public Version HttpProtocolVersion { get; set; }
Property Value
HttpProtocolVersionPolicy
public HttpVersionPolicy HttpProtocolVersionPolicy { get; set; }
Property Value
HttpTimeout
public TimeSpan HttpTimeout { get; set; }
Property Value
HttpUserAgent
public string? HttpUserAgent { get; set; }
Property Value
IsAllowHttpCookies
public bool IsAllowHttpCookies { get; set; }
Property Value
IsAllowHttpRedirections
public bool IsAllowHttpRedirections { get; set; }
Property Value
IsAllowUntrustedCert
public bool IsAllowUntrustedCert { get; set; }
Property Value
IsUseProxy
public static bool IsUseProxy { get; }
Property Value
IsUseSystemProxy
public static bool IsUseSystemProxy { get; }
Property Value
MaxConnections
public int MaxConnections { get; set; }
Property Value
Methods
AddHeader(string, string?)
Adds or updates an HTTP header in the builder's configuration.
public PluginHttpClientBuilder AddHeader(string key, string? value)
Parameters
keystringThe name of the HTTP header to add or update. Cannot be null or empty.
valuestringThe value of the HTTP header. Can be null to indicate the header should have no value.
Returns
Remarks
If the header key is "User-Agent" (case-insensitive), the value of the HttpUserAgent property will be overridden.
If the specified header key already exists, its value will be updated; otherwise, the header will be added.
AllowCookies(bool)
Allows cookies to be used on the HttpClient or not.
public PluginHttpClientBuilder AllowCookies(bool allowCookies = true)
Parameters
allowCookiesboolEither allow cookies or not.
Returns
Remarks
Default: true
AllowRedirections(bool)
Allows the redirection (30x) HTTP status code or not.
public PluginHttpClientBuilder AllowRedirections(bool allowRedirections = true)
Parameters
allowRedirectionsboolEither allow the redirection or not.
Returns
Remarks
Default: true
AllowUntrustedCert(bool)
Allows HttpClient to skip untrusted/unvalidated certificate validation on each of the request.
public PluginHttpClientBuilder AllowUntrustedCert(bool allowUntrustedCert = true)
Parameters
allowUntrustedCertboolEither to allow HttpClient to skip certificate validation or not.
Returns
Remarks
Default: false
Create()
Creates and configures an instance of HttpClient with the specified settings.
public HttpClient Create()
Returns
- HttpClient
A fully configured HttpClient instance ready for making HTTP requests.
Remarks
This method initializes a new HttpClient using a SocketsHttpHandler configured with various properties such as proxy settings, connection limits, decompression methods, and HTTP protocol versions. It also applies custom headers, authentication settings, and other options based on the provided configuration. The returned HttpClient is ready for use and includes settings such as timeout, base address, and user-agent headers. If the configuration allows untrusted certificates, the handler is set to bypass certificate validation.
SetAllowedDecompression(DecompressionMethods)
Sets the allowed decompression methods on the HTTP response.
public PluginHttpClientBuilder SetAllowedDecompression(DecompressionMethods decompressionMethods = (DecompressionMethods)-1)
Parameters
decompressionMethodsDecompressionMethodsKind of decompressors to be used.
Returns
Remarks
Default: All
SetAuthHeader(string?)
Sets the value of Authorization HTTP header.
public PluginHttpClientBuilder SetAuthHeader(string? authHeader = null)
Parameters
authHeaderstring
Returns
Remarks
Default: null
If the authHeader is set to null, the Authorization HTTP header will be unset.
SetBaseUrl(string)
Sets the base URL used by the HttpClient.
public PluginHttpClientBuilder SetBaseUrl(string baseUrl)
Parameters
baseUrlstringThe base URL used by the HttpClient.
Returns
SetBaseUrl(Uri)
Sets the base URL used by the HttpClient.
public PluginHttpClientBuilder SetBaseUrl(Uri baseUrl)
Parameters
baseUrlUriThe base URL used by the HttpClient.
Returns
SetHttpVersion(Version?, HttpVersionPolicy)
Sets the policy of which version of HTTP to be used.
public PluginHttpClientBuilder SetHttpVersion(Version? version = null, HttpVersionPolicy versionPolicy = HttpVersionPolicy.RequestVersionOrLower)
Parameters
versionVersionWhat HTTP version to be requested.
versionPolicyHttpVersionPolicyThe version request policy used.
Returns
Remarks
Default version: null (or Version11)
Default versionPolicy: RequestVersionOrLower
If the version is set to null, the Version11 will be used instead.
If MANUALCOM constant is defined and version set to Version30, it will be reverted to Version20 (due to unsupported features).
SetMaxConnection(int)
Sets the maximum connection to be established by the HttpClient.
public PluginHttpClientBuilder SetMaxConnection(int maxConnections = 32)
Parameters
maxConnectionsintThe amount of connections to be handled.
Returns
Remarks
Minimum: 2
Default: ExMaxConnectionsDefault
SetTimeout(double)
Sets how long the request will be allowed to be performed until certain timeout duration (in seconds).
public PluginHttpClientBuilder SetTimeout(double fromSeconds = 90)
Parameters
fromSecondsdoubleHow many seconds before timeout is happening.
Returns
Remarks
Default: ExHttpTimeoutDefault
SetTimeout(TimeSpan?)
Sets how long the request will be allowed to be performed until certain timeout duration (in TimeSpan).
public PluginHttpClientBuilder SetTimeout(TimeSpan? timeout = null)
Parameters
timeoutTimeSpan?The amount of time span used before timeout is happening.
Returns
Remarks
Default: TimeSpan.FromSeconds(ExHttpTimeoutDefault)
SetUserAgent(string?)
Sets the user-agent used by the HttpClient on each of its requests.
public PluginHttpClientBuilder SetUserAgent(string? userAgent = null)
Parameters
userAgentstringThe user-agent to be used.
Returns
Remarks
Default: null
If the userAgent is set to null, the default plugin user-agent will be used instead.