- java.lang.Object
-
- net.dongliu.cute.http.ClientBuilder
-
public class ClientBuilder extends Object
Builder to build Http Client.
-
-
构造器概要
构造器 构造器 说明 ClientBuilder()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ClientBuilderacceptCompressed(boolean acceptCompressed)Auto set Accept-Encoding header for request.ClientBuilderauthenticator(Authenticator authenticator)Provide Authenticator for http basic or digest Authentication.Clientbuild()Build a new http Client.ClientBuilderconnectTimeout(Duration timeout)Set timeout for connecting phase.ClientBuildercookieHandler(CookieHandler cookieHandler)Provide CookieHandler for handle cookies.If not set, will use default in-memory store CookieManager.ClientBuilderexecutor(Executor executor)Set a custom executor, for asynchronous and dependent tasks.ClientBuilderfollowRedirect(boolean followRedirect)If follow redirects.ClientBuilderjsonMarshaller(JsonMarshaller jsonMarshaller)Set json marshaller for this http client.ClientBuilderkeyStore(KeyStore keyStore)Provide KeyStore for create ssl connection, trust the server certificate.ClientBuildername(String name)Set name for this http clientClientBuilderproxy(Proxy proxy)Set a proxy for this client.ClientBuilderproxy(ProxySelector proxySelector)Set a proxy selector for this client.ClientBuildertimeout(Duration timeout)The timeout for one request to return response, do not include connect time.ClientBuilderuseHttp2(boolean useHttp2)If use http2. default trueClientBuilderuserAgent(String userAgent)The client user-agent.ClientBuilderverifyCert(boolean verify)If check https certificate, default true.
-
-
-
方法详细资料
-
build
public Client build()
Build a new http Client.- 返回:
- the http client
-
name
public ClientBuilder name(String name)
Set name for this http client
-
proxy
public ClientBuilder proxy(ProxySelector proxySelector)
Set a proxy selector for this client. If not set, will use no proxy. Note: seems JDK HttpClient Only support http proxy.
-
proxy
public ClientBuilder proxy(Proxy proxy)
Set a proxy for this client. If not set, will use no proxy. Note: seems JDK HttpClient Only support http proxy.
-
useHttp2
public ClientBuilder useHttp2(boolean useHttp2)
If use http2. default true
-
verifyCert
public ClientBuilder verifyCert(boolean verify)
If check https certificate, default true.
-
followRedirect
public ClientBuilder followRedirect(boolean followRedirect)
If follow redirects. Default true
-
connectTimeout
public ClientBuilder connectTimeout(Duration timeout)
Set timeout for connecting phase. The timeout include ssl handshake, etc. Default is 5 secs.
-
timeout
public ClientBuilder timeout(Duration timeout)
The timeout for one request to return response, do not include connect time. Default is 10 secs. Note: The can be override by request setting.
-
userAgent
public ClientBuilder userAgent(String userAgent)
The client user-agent. Note: The can be override by request setting.
-
acceptCompressed
public ClientBuilder acceptCompressed(boolean acceptCompressed)
Auto set Accept-Encoding header for request. Default is true. Note: This setting can be override by per request setting.
-
authenticator
public ClientBuilder authenticator(Authenticator authenticator)
Provide Authenticator for http basic or digest Authentication. If not set, will use system default Authenticator.- 参数:
authenticator- the authenticator- 返回:
- self
-
cookieHandler
public ClientBuilder cookieHandler(CookieHandler cookieHandler)
Provide CookieHandler for handle cookies.If not set, will use default in-memory store CookieManager.- 参数:
cookieHandler- the cookieManager- 返回:
- self
-
keyStore
public ClientBuilder keyStore(KeyStore keyStore)
Provide KeyStore for create ssl connection, trust the server certificate.- 参数:
keyStore- the keyStore- 返回:
- self
-
executor
public ClientBuilder executor(Executor executor)
Set a custom executor, for asynchronous and dependent tasks.- 参数:
executor- the executor- 返回:
- self
-
jsonMarshaller
public ClientBuilder jsonMarshaller(JsonMarshaller jsonMarshaller)
Set json marshaller for this http client. If not set, will try to find available JsonMarshaller implementation by spi; If no spi implementation was found, aJsonMarshallerNotFoundExceptionwould be thrown when handle with json.- 参数:
jsonMarshaller- the JsonMarshaller
-
-