Class CurlSettings
- Namespace
- CurlDotNet.Core
- Assembly
- CurlDotNet.dll
Fluent builder for .NET-specific curl settings.
public class CurlSettings
- Inheritance
-
CurlSettings
- Inherited Members
Examples
var settings = new CurlSettings()
.WithTimeout(30)
.WithRetries(3)
.WithProgress((percent, total, current) => Console.WriteLine($"{percent}%"))
.WithCancellation(cancellationToken);
var result = await Curl.Execute("curl https://example.com", settings);
Remarks
These settings complement curl commands with .NET-specific features.
AI-Usage: Use this for cancellation, progress, retries, and other .NET features.
Properties
AutomaticDecompression
Whether to automatically decompress response.
public bool AutomaticDecompression { get; set; }
Property Value
BufferSize
Buffer size for download operations.
public int BufferSize { get; set; }
Property Value
CancellationToken
Cancellation token for the operation.
public CancellationToken CancellationToken { get; set; }
Property Value
ConnectTimeoutSeconds
Connection timeout in seconds.
public int? ConnectTimeoutSeconds { get; set; }
Property Value
- int?
Cookies
Cookie container for maintaining session.
public CookieContainer Cookies { get; set; }
Property Value
FollowRedirects
Whether to follow redirects.
public bool? FollowRedirects { get; set; }
Property Value
- bool?
Headers
Additional headers to add to the request.
public Dictionary<string, string> Headers { get; set; }
Property Value
Insecure
Whether to ignore SSL certificate errors.
public bool? Insecure { get; set; }
Property Value
- bool?
MaxTimeSeconds
Maximum time in seconds for the entire operation.
public int? MaxTimeSeconds { get; set; }
Property Value
- int?
OnProgress
Progress callback (percent, totalBytes, currentBytes).
public Action<double, long, long> OnProgress { get; set; }
Property Value
OnRedirect
Callback for each redirect.
public Action<string> OnRedirect { get; set; }
Property Value
Proxy
Proxy settings.
public IWebProxy Proxy { get; set; }
Property Value
RetryCount
Number of retry attempts on failure.
public int RetryCount { get; set; }
Property Value
RetryDelayMs
Delay between retries in milliseconds.
public int RetryDelayMs { get; set; }
Property Value
UserAgent
Custom user agent string.
public string UserAgent { get; set; }
Property Value
Methods
FromDefaults()
Create default settings from global Curl settings.
public static CurlSettings FromDefaults()
Returns
WithAutoDecompression(bool)
Set automatic decompression.
public CurlSettings WithAutoDecompression(bool enable = true)
Parameters
enablebool
Returns
WithBufferSize(int)
Set buffer size for downloads.
public CurlSettings WithBufferSize(int size)
Parameters
sizeint
Returns
WithCancellation(CancellationToken)
Set cancellation token.
public CurlSettings WithCancellation(CancellationToken token)
Parameters
tokenCancellationToken
Returns
WithConnectTimeout(int)
Set connection timeout.
public CurlSettings WithConnectTimeout(int seconds)
Parameters
secondsint
Returns
WithCookies(CookieContainer)
Use cookie container for session management.
public CurlSettings WithCookies(CookieContainer container = null)
Parameters
containerCookieContainer
Returns
WithFollowRedirects(bool)
Enable or disable following redirects.
public CurlSettings WithFollowRedirects(bool follow = true)
Parameters
followbool
Returns
WithHeader(string, string)
Add a header.
public CurlSettings WithHeader(string key, string value)
Parameters
Returns
WithHeaders(Dictionary<string, string>)
Add multiple headers.
public CurlSettings WithHeaders(Dictionary<string, string> headers)
Parameters
headersDictionary<string, string>
Returns
WithInsecure(bool)
Enable or disable SSL certificate validation.
public CurlSettings WithInsecure(bool insecure = true)
Parameters
insecurebool
Returns
WithProgress(Action<double, long, long>)
Set progress callback.
public CurlSettings WithProgress(Action<double, long, long> callback)
Parameters
Returns
WithProxy(string)
Set proxy.
public CurlSettings WithProxy(string proxyUrl)
Parameters
proxyUrlstring
Returns
WithProxy(string, string, string)
Set proxy with credentials.
public CurlSettings WithProxy(string proxyUrl, string username, string password)
Parameters
Returns
WithRedirectHandler(Action<string>)
Set redirect callback.
public CurlSettings WithRedirectHandler(Action<string> callback)
Parameters
Returns
WithRetries(int, int)
Set retry behavior.
public CurlSettings WithRetries(int count, int delayMs = 1000)
Parameters
Returns
WithTimeout(int)
Set maximum time for operation.
public CurlSettings WithTimeout(int seconds)
Parameters
secondsint
Returns
WithUserAgent(string)
Set custom user agent.
public CurlSettings WithUserAgent(string userAgent)
Parameters
userAgentstring