forked from loafle/openapi-generator-original
[c#][netcore] add proxy support (#7741)
* add proxy support to c# netcore client * add test, update doc
This commit is contained in:
parent
5bac98cd99
commit
c1f2b1cad9
@ -422,6 +422,11 @@ namespace {{packageName}}.Client
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
@ -529,6 +534,11 @@ namespace {{packageName}}.Client
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
|
@ -7,6 +7,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
@ -109,6 +110,7 @@ namespace {{packageName}}.Client
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
|
||||
public Configuration()
|
||||
{
|
||||
Proxy = null;
|
||||
UserAgent = "{{#httpUserAgent}}{{.}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{packageVersion}}/csharp{{/httpUserAgent}}";
|
||||
BasePath = "{{{basePath}}}";
|
||||
DefaultHeaders = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
|
||||
@ -236,6 +238,12 @@ namespace {{packageName}}.Client
|
||||
/// </summary>
|
||||
public virtual int Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the proxy
|
||||
/// </summary>
|
||||
/// <value>Proxy.</value>
|
||||
public virtual WebProxy Proxy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP user agent.
|
||||
/// </summary>
|
||||
@ -553,6 +561,7 @@ namespace {{packageName}}.Client
|
||||
DefaultHeaders = defaultHeaders,
|
||||
BasePath = second.BasePath ?? first.BasePath,
|
||||
Timeout = second.Timeout,
|
||||
Proxy = second.Proxy ?? first.Proxy,
|
||||
UserAgent = second.UserAgent ?? first.UserAgent,
|
||||
Username = second.Username ?? first.Username,
|
||||
Password = second.Password ?? first.Password,
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace {{packageName}}.Client
|
||||
@ -66,6 +67,12 @@ namespace {{packageName}}.Client
|
||||
/// <value>HTTP connection timeout.</value>
|
||||
int Timeout { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the proxy.
|
||||
/// </summary>
|
||||
/// <value>Proxy.</value>
|
||||
WebProxy Proxy { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user agent.
|
||||
/// </summary>
|
||||
|
@ -84,6 +84,17 @@ nuget pack -Build -OutputDirectory out {{packageName}}.csproj
|
||||
Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual.
|
||||
|
||||
{{/netStandard}}
|
||||
<a name="usage"></a>
|
||||
## Usage
|
||||
|
||||
To use the API client with a HTTP proxy, setup a `System.Net.WebProxy`
|
||||
```csharp
|
||||
Configuration c = new Configuration();
|
||||
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
|
||||
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||
c.Proxy = webProxy;
|
||||
```
|
||||
|
||||
<a name="getting-started"></a>
|
||||
## Getting Started
|
||||
|
||||
|
@ -44,6 +44,17 @@ using Org.OpenAPITools.Api;
|
||||
using Org.OpenAPITools.Client;
|
||||
using Org.OpenAPITools.Model;
|
||||
```
|
||||
<a name="usage"></a>
|
||||
## Usage
|
||||
|
||||
To use the API client with a HTTP proxy, setup a `System.Net.WebProxy`
|
||||
```csharp
|
||||
Configuration c = new Configuration();
|
||||
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
|
||||
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||
c.Proxy = webProxy;
|
||||
```
|
||||
|
||||
<a name="getting-started"></a>
|
||||
## Getting Started
|
||||
|
||||
|
@ -22,6 +22,18 @@ namespace Org.OpenAPITools.Test
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test WebProxy
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void WebProxyTest()
|
||||
{
|
||||
Configuration c = new Configuration();
|
||||
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
|
||||
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||
c.Proxy = webProxy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetServerUrl
|
||||
/// </summary>
|
||||
|
@ -426,6 +426,11 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
@ -532,6 +537,11 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
|
@ -13,6 +13,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
@ -104,6 +105,7 @@ namespace Org.OpenAPITools.Client
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
|
||||
public Configuration()
|
||||
{
|
||||
Proxy = null;
|
||||
UserAgent = "OpenAPI-Generator/1.0.0/csharp";
|
||||
BasePath = "http://petstore.swagger.io:80/v2";
|
||||
DefaultHeaders = new ConcurrentDictionary<string, string>();
|
||||
@ -255,6 +257,12 @@ namespace Org.OpenAPITools.Client
|
||||
/// </summary>
|
||||
public virtual int Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the proxy
|
||||
/// </summary>
|
||||
/// <value>Proxy.</value>
|
||||
public virtual WebProxy Proxy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP user agent.
|
||||
/// </summary>
|
||||
@ -562,6 +570,7 @@ namespace Org.OpenAPITools.Client
|
||||
DefaultHeaders = defaultHeaders,
|
||||
BasePath = second.BasePath ?? first.BasePath,
|
||||
Timeout = second.Timeout,
|
||||
Proxy = second.Proxy ?? first.Proxy,
|
||||
UserAgent = second.UserAgent ?? first.UserAgent,
|
||||
Username = second.Username ?? first.Username,
|
||||
Password = second.Password ?? first.Password,
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
@ -74,6 +75,12 @@ namespace Org.OpenAPITools.Client
|
||||
/// <value>HTTP connection timeout.</value>
|
||||
int Timeout { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the proxy.
|
||||
/// </summary>
|
||||
/// <value>Proxy.</value>
|
||||
WebProxy Proxy { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user agent.
|
||||
/// </summary>
|
||||
|
@ -56,6 +56,17 @@ nuget pack -Build -OutputDirectory out Org.OpenAPITools.csproj
|
||||
|
||||
Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual.
|
||||
|
||||
<a name="usage"></a>
|
||||
## Usage
|
||||
|
||||
To use the API client with a HTTP proxy, setup a `System.Net.WebProxy`
|
||||
```csharp
|
||||
Configuration c = new Configuration();
|
||||
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
|
||||
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||
c.Proxy = webProxy;
|
||||
```
|
||||
|
||||
<a name="getting-started"></a>
|
||||
## Getting Started
|
||||
|
||||
|
@ -427,6 +427,11 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
@ -533,6 +538,11 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
|
@ -13,6 +13,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
@ -109,6 +110,7 @@ namespace Org.OpenAPITools.Client
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
|
||||
public Configuration()
|
||||
{
|
||||
Proxy = null;
|
||||
UserAgent = "OpenAPI-Generator/1.0.0/csharp";
|
||||
BasePath = "http://petstore.swagger.io:80/v2";
|
||||
DefaultHeaders = new ConcurrentDictionary<string, string>();
|
||||
@ -260,6 +262,12 @@ namespace Org.OpenAPITools.Client
|
||||
/// </summary>
|
||||
public virtual int Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the proxy
|
||||
/// </summary>
|
||||
/// <value>Proxy.</value>
|
||||
public virtual WebProxy Proxy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP user agent.
|
||||
/// </summary>
|
||||
@ -568,6 +576,7 @@ namespace Org.OpenAPITools.Client
|
||||
DefaultHeaders = defaultHeaders,
|
||||
BasePath = second.BasePath ?? first.BasePath,
|
||||
Timeout = second.Timeout,
|
||||
Proxy = second.Proxy ?? first.Proxy,
|
||||
UserAgent = second.UserAgent ?? first.UserAgent,
|
||||
Username = second.Username ?? first.Username,
|
||||
Password = second.Password ?? first.Password,
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
@ -74,6 +75,12 @@ namespace Org.OpenAPITools.Client
|
||||
/// <value>HTTP connection timeout.</value>
|
||||
int Timeout { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the proxy.
|
||||
/// </summary>
|
||||
/// <value>Proxy.</value>
|
||||
WebProxy Proxy { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user agent.
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user