123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using COSXML.Common;
- namespace COSXML.Network
- {
- public class HttpClientConfig
- {
- private string userAgent;
- private bool allowAutoRedirect;
- private int connectionTimeoutMs;
- private int readWriteTimeoutMs;
- private int maxRetry;
- private int connectionLimit;
- private string proxyHost;
- private int proxyPort;
- private string proxyUserName;
- private string proxyUserPassword;
- private string proxyDomain;
- private bool keepAlive;
- private HttpClientConfig(Builder builder)
- {
- this.userAgent = builder.userAgent;
- this.allowAutoRedirect = builder.allowAutoRedirect;
- this.connectionTimeoutMs = builder.connectionTimeoutMs;
- this.readWriteTimeoutMs = builder.readWriteTimeoutMs;
- this.maxRetry = builder.maxRetry;
- this.connectionLimit = builder.connectionLimit;
- this.proxyHost = builder.proxyHost;
- this.proxyPort = builder.proxyPort;
- this.proxyUserName = builder.proxyUserName;
- this.proxyUserPassword = builder.proxyUserPassword;
- this.proxyDomain = builder.proxyDomain;
- this.keepAlive = builder.keepAlive;
- }
- public string UserAgnet
- {
- get
- {
- return userAgent;
- }
- }
- public bool AllowAutoRedirect
- {
- get
- {
- return allowAutoRedirect;
- }
- }
- public int ConnectionTimeoutMs
- {
- get
- {
- return connectionTimeoutMs;
- }
- }
- public int ReadWriteTimeoutMs
- {
- get
- {
- return readWriteTimeoutMs;
- }
- }
- public int ConnectionLimit
- {
- get
- {
- return connectionLimit;
- }
- }
- public string ProxyHost
- {
- get
- {
- return proxyHost;
- }
- }
- public int ProxyPort
- {
- get
- {
- return proxyPort;
- }
- }
- public string ProxyUserName
- {
- get
- {
- return proxyUserName;
- }
- }
- public string ProxyUserPassword
- {
- get
- {
- return proxyUserPassword;
- }
- }
- public string ProxyDomain
- {
- get
- {
- return proxyDomain;
- }
- }
- public bool KeepAlive
- {
- get
- {
- return keepAlive;
- }
- }
- public int MaxRetry
- {
- get
- {
- return maxRetry;
- }
- }
- public class Builder
- {
- internal string userAgent = CosVersion.GetUserAgent();
- internal bool allowAutoRedirect = true;
- internal int connectionTimeoutMs = 45000;
- internal int readWriteTimeoutMs = 45000;
- internal int maxRetry = 3;
- internal int connectionLimit = 512;
- internal int proxyPort = -1;
- internal string proxyHost = null;
- internal string proxyUserName;
- internal string proxyUserPassword;
- internal string proxyDomain;
- internal bool keepAlive = true;
- public Builder()
- {
-
- }
- public Builder AllowAutoRedirect(bool allow)
- {
- this.allowAutoRedirect = allow;
- return this;
- }
- public Builder SetConnectionLimit(int connectionLimit)
- {
- if (connectionLimit > 0)
- {
- this.connectionLimit = connectionLimit;
- }
- return this;
- }
- public Builder SetConnectionTimeoutMs(int connectionTimeoutMs)
- {
- if (connectionTimeoutMs > 0)
- {
- this.connectionTimeoutMs = connectionTimeoutMs;
- }
- return this;
- }
- public Builder SetReadWriteTimeoutMs(int readWriteTimeoutMs)
- {
- if (readWriteTimeoutMs > 0)
- {
- this.readWriteTimeoutMs = readWriteTimeoutMs;
- }
- return this;
- }
- public Builder SetProxyHost(string host)
- {
- this.proxyHost = host;
- return this;
- }
- public Builder SetProxyPort(int port)
- {
- this.proxyPort = port;
- return this;
- }
- public Builder SetProxyUserName(string userName)
- {
- this.proxyUserName = userName;
- return this;
- }
- public Builder SetProxyUserPassword(string password)
- {
- this.proxyUserPassword = password;
- return this;
- }
- public Builder SetProxyDomain(string domain)
- {
- this.proxyDomain = domain;
- return this;
- }
- public Builder SetHttpKeepAlive(bool keepAlive)
- {
- this.keepAlive = keepAlive;
- return this;
- }
- public Builder SetMaxRetry(int maxRetry)
- {
- this.maxRetry = maxRetry;
- return this;
- }
- public HttpClientConfig Build()
- {
- return new HttpClientConfig(this);
- }
- }
- }
- }
|