-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentstackClientOptions.cs
More file actions
195 lines (165 loc) · 6.83 KB
/
ContentstackClientOptions.cs
File metadata and controls
195 lines (165 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.ComponentModel;
using System.Net;
using Contentstack.Management.Core.Runtime.Pipeline.RetryHandler;
using Contentstack.Management.Core.Utils;
namespace Contentstack.Management.Core
{
/// <summary>
/// ContentstackConfig class is base class for Contentstack Configuration
/// </summary>
public class ContentstackClientOptions
{
#region public
/// <summary>
/// An Authtoken is a read-write token used to make authorized CMA requests.
/// </summary>
public string Authtoken { get; set; }
/// <summary>
/// Indicates whether the current authtoken is an OAuth Bearer token.
/// When true, the authtoken will be sent as "Authorization: Bearer {token}" header.
/// When false, the authtoken will be sent as "authtoken: {token}" header.
/// </summary>
public bool IsOAuthToken { get; set; } = false;
/// <summary>
/// The Host used to set host url for the Contentstack Management API.
/// </summary>
public string Host { get; set; } = "api.contentstack.io";
/// <summary>
/// The EarlyAccess used to set early access headers for the Contentstack Management API.
/// </summary>
public string[] EarlyAccess { get; set; }
/// <summary>
/// The Host used to set host url for the Contentstack Management API.
/// </summary>
public int Port { get; set; } = 443;
/// <summary>
/// The Host used to set host url for the Contentstack Management API.
/// </summary>
public string Version { get; set; } = "v3";
/// <summary>
/// Gets or sets the DisableLogging. When set to true, the logging of the client is disabled.
/// The default value is false.
/// </summary>
public bool DisableLogging { get; set; } = false;
/// <summary>
/// Gets or sets the maximum number of bytes to buffer when reading the response content.
/// The default value for this property is 1 gigabytes.
/// </summary>
public long MaxResponseContentBufferSize { get; set; } = CSConstants.ContentBufferSize;
/// <summary>
/// Gets or sets the timespan to wait before the request times out.
/// The default value for time out is 30 seconds.
/// </summary>
public TimeSpan Timeout { get; set; } = CSConstants.Timeout;
/// <summary>
/// When set to true, the client will retry requests.
/// When set to false, the client will not retry request.
/// The default value is true
/// </summary>
public bool RetryOnError { get; set; } = true;
/// <summary>
/// Returns the flag indicating how many retry HTTP requests an SDK should
/// make for a single SDK operation invocation before giving up.
/// The default value is 5.
/// </summary>
public int RetryLimit { get; set; } = 5;
/// <summary>
/// Returns the flag indicating delay in retrying HTTP requests.
/// The default value is 300ms.
/// </summary>
public TimeSpan RetryDelay { get; set; } = CSConstants.Delay;
/// <summary>
/// The retry policy which specifies when
/// a retry should be performed.
/// </summary>
public RetryPolicy RetryPolicy { get; set; }
/// <summary>
/// When set to true, the client will retry on network failures.
/// The default value is true.
/// </summary>
public bool RetryOnNetworkFailure { get; set; } = true;
/// <summary>
/// When set to true, the client will retry on DNS failures.
/// The default value is true.
/// </summary>
public bool RetryOnDnsFailure { get; set; } = true;
/// <summary>
/// When set to true, the client will retry on socket failures.
/// The default value is true.
/// </summary>
public bool RetryOnSocketFailure { get; set; } = true;
/// <summary>
/// When set to true, the client will retry on HTTP server errors (5xx).
/// The default value is true.
/// </summary>
public bool RetryOnHttpServerError { get; set; } = true;
/// <summary>
/// Maximum number of network retry attempts.
/// The default value is 3.
/// </summary>
public int MaxNetworkRetries { get; set; } = 3;
/// <summary>
/// Base delay for network retries.
/// The default value is 100ms.
/// </summary>
public TimeSpan NetworkRetryDelay { get; set; } = TimeSpan.FromMilliseconds(100);
/// <summary>
/// Backoff strategy for network retries.
/// The default value is Exponential.
/// </summary>
public BackoffStrategy NetworkBackoffStrategy { get; set; } = BackoffStrategy.Exponential;
/// <summary>
/// Custom function to determine if a status code should be retried.
/// If null, default retry condition is used (429, 500, 502, 503, 504).
/// </summary>
public Func<HttpStatusCode, bool>? RetryCondition { get; set; }
/// <summary>
/// Options for retry delay calculation.
/// </summary>
public RetryDelayOptions RetryDelayOptions { get; set; }
/// <summary>
/// Host for the Proxy.
/// </summary>
public string ProxyHost { get; set; }
/// <summary>
/// Port for the Proxy.
/// </summary>
public int ProxyPort { get; set; } = -1;
/// <summary>
/// Credentials to use with a proxy.
/// </summary>
public ICredentials ProxyCredentials { get; set; }
/// <summary>
/// Returns a WebProxy instance configured to match the proxy settings
/// in the configuration.
/// </summary>
/// <returns></returns>
public IWebProxy GetWebProxy()
{
const string httpPrefix = "http://";
WebProxy webProxy = null;
if (!string.IsNullOrEmpty(ProxyHost) && ProxyPort != -1)
{
var host = ProxyHost.StartsWith(httpPrefix, StringComparison.OrdinalIgnoreCase)
? ProxyHost.Substring(httpPrefix.Length)
: ProxyHost;
webProxy = new WebProxy(host, ProxyPort);
if (ProxyCredentials != null)
{
webProxy.Credentials = ProxyCredentials;
}
}
return webProxy;
}
public Uri GetUri ()
{
UriBuilder uriBuilder = new UriBuilder(this.Host);
uriBuilder.Port = this.Port;
uriBuilder.Path = this.Version;
uriBuilder.Scheme = "https";
return uriBuilder.Uri;
}
#endregion
}
}