add httpUserAgent option, add customized user-agent support to C#

This commit is contained in:
wing328
2016-03-13 17:28:43 +08:00
parent d3f26f72d9
commit cdecb5133f
14 changed files with 124 additions and 3 deletions

View File

@@ -84,6 +84,9 @@ namespace {{packageName}}.Client
String contentType)
{
var request = new RestRequest(path, method);
// add user agent header
request.AddHeader("User-Agent", Configuration.HttpUserAgent);
// add path parameter, if any
foreach(var param in pathParams)

View File

@@ -34,7 +34,8 @@ namespace {{packageName}}.Client
Dictionary<String, String> apiKeyPrefix = null,
string tempFolderPath = null,
string dateTimeFormat = null,
int timeout = 100000
int timeout = 100000,
string httpUserAgent = "{{#httpUserAgent}}{{.}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{packageVersion}}/csharp{{/httpUserAgent}}"
)
{
setApiClientUsingDefault(apiClient);
@@ -42,6 +43,7 @@ namespace {{packageName}}.Client
Username = username;
Password = password;
AccessToken = accessToken;
HttpUserAgent = httpUserAgent;
if (defaultHeader != null)
DefaultHeader = defaultHeader;
@@ -146,6 +148,12 @@ namespace {{packageName}}.Client
_defaultHeaderMap.Add(key, value);
}
/// <summary>
/// Gets or sets the HTTP user agent.
/// </summary>
/// <value>Http user agent.</value>
public String HttpUserAgent { get; set; }
/// <summary>
/// Gets or sets the username (HTTP basic authentication).
/// </summary>

View File

@@ -82,6 +82,12 @@ namespace {{packageName}}.Api
public {{classname}}(String basePath)
{
this.Configuration = new Configuration(new ApiClient(basePath));
// ensure API client has configuration ready
if (Configuration.ApiClient.Configuration == null)
{
this.Configuration.ApiClient.Configuration = this.Configuration;
}
}
/// <summary>
@@ -96,6 +102,12 @@ namespace {{packageName}}.Api
this.Configuration = Configuration.Default;
else
this.Configuration = configuration;
// ensure API client has configuration ready
if (Configuration.ApiClient.Configuration == null)
{
this.Configuration.ApiClient.Configuration = this.Configuration;
}
}
/// <summary>