Skip to content

Commit b9f5f20

Browse files
committed
xenapi: removed the default value for xenserver UserAgent
Signed-off-by: Rashmi A Badadale <badadalerashmi@gmail.com>
1 parent 654cef3 commit b9f5f20

2 files changed

Lines changed: 38 additions & 20 deletions

File tree

ocaml/sdk-gen/csharp/autogen/src/JsonRpc.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public override string ToString()
163163
public partial class JsonRpcClient
164164
{
165165
private int _globalId;
166+
private string _userAgent;
166167

167168
#if (NET8_0_OR_GREATER)
168169
private static readonly Type ClassType = typeof(JsonRpcClient);
@@ -205,6 +206,10 @@ public JsonRpcClient(string baseUrl)
205206
Url = baseUrl;
206207
JsonRpcUrl = new Uri(new Uri(baseUrl), "/jsonrpc").ToString();
207208
JsonRpcVersion = JsonRpcVersion.v1;
209+
Timeout = Session.STANDARD_TIMEOUT;
210+
UserAgent = Session.DefaultUserAgent;
211+
KeepAlive = true;
212+
AllowAutoRedirect = true;
208213
}
209214

210215
/// <summary>
@@ -215,7 +220,11 @@ public JsonRpcClient(string baseUrl)
215220
public event Action<string> RequestEvent;
216221

217222
public JsonRpcVersion JsonRpcVersion { get; set; }
218-
public string UserAgent { get; set; }
223+
public string UserAgent
224+
{
225+
get => _userAgent;
226+
set => _userAgent = string.IsNullOrEmpty(value) ? Session.DefaultUserAgent : value;
227+
}
219228
public bool KeepAlive { get; set; }
220229
public IWebProxy WebProxy { get; set; }
221230
public int Timeout { get; set; }

ocaml/sdk-gen/csharp/autogen/src/Session.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,16 @@ public partial class Session : XenObject<Session>
4646
public const int STANDARD_TIMEOUT = 24 * 60 * 60 * 1000;
4747

4848
/// <summary>
49-
/// This string is used as the HTTP UserAgent for each request.
49+
/// The default HTTP UserAgent for each request.
5050
/// </summary>
51-
public static string UserAgent = $"XenAPI/{Helper.APIVersionString(API_Version.LATEST)}";
52-
53-
/// <summary>
54-
/// If null, no proxy is used, otherwise this proxy is used for each request.
55-
/// </summary>
56-
public static IWebProxy Proxy = null;
57-
58-
public API_Version APIVersion = API_Version.UNKNOWN;
59-
60-
public object Tag;
51+
public static readonly string DefaultUserAgent = $"XenAPI/{Helper.APIVersionString(API_Version.LATEST)}";
6152

6253
#region Constructors
6354

55+
/// <exception cref="ArgumentNullException">Thrown if 'client' is null</exception>
6456
public Session(JsonRpcClient client)
6557
{
66-
client.Timeout = STANDARD_TIMEOUT;
67-
client.KeepAlive = true;
68-
client.UserAgent = UserAgent;
69-
client.WebProxy = Proxy;
70-
client.AllowAutoRedirect = true;
71-
JsonRpcClient = client;
58+
JsonRpcClient = client ?? throw new ArgumentNullException(nameof(client));
7259
}
7360

7461
public Session(string url) :
@@ -230,6 +217,19 @@ public override string SaveChanges(Session session, string serverOpaqueRef, Sess
230217

231218
#region Properties
232219

220+
/// <summary>
221+
/// The WebProxy to use for each HTTP request.
222+
/// </summary>
223+
public IWebProxy Proxy
224+
{
225+
get => JsonRpcClient.WebProxy;
226+
set => JsonRpcClient.WebProxy = value;
227+
}
228+
229+
public API_Version APIVersion { get; private set; } = API_Version.UNKNOWN;
230+
231+
public object Tag { get; set; }
232+
233233
/// <summary>
234234
/// Retrieves the current users details from the UserDetails map. These values are only updated when a new session is created.
235235
/// </summary>
@@ -239,15 +239,24 @@ public override string SaveChanges(Session session, string serverOpaqueRef, Sess
239239

240240
public string Url => JsonRpcClient.Url;
241241

242+
/// <summary>
243+
/// The UserAgent to use for each HTTP request. If set to null or empty the DefaultUserAgent will be used.
244+
/// </summary>
245+
public string UserAgent
246+
{
247+
get => JsonRpcClient.UserAgent;
248+
set => JsonRpcClient.UserAgent = value;
249+
}
250+
242251
public string ConnectionGroupName
243252
{
244-
get => JsonRpcClient?.ConnectionGroupName;
253+
get => JsonRpcClient.ConnectionGroupName;
245254
set => JsonRpcClient.ConnectionGroupName = value;
246255
}
247256

248257
public int Timeout
249258
{
250-
get => JsonRpcClient?.Timeout ?? STANDARD_TIMEOUT;
259+
get => JsonRpcClient.Timeout;
251260
set => JsonRpcClient.Timeout = value;
252261
}
253262

0 commit comments

Comments
 (0)