You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by 陈飞 <di...@gmail.com> on 2018/12/28 06:27:06 UTC

Issue about socketTimeout overriden during https handshake

Before handshake during https request, if connectTimeout is set alone,
without socketTimeout, SSLConnectionSocketFactory#connectSocket will
override socketTimeout with connectTimeout and never change back, anyone
know why? is it a flaw or feature?

HttpClient version: 4.5.3

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.3</version>
</dependency>

Example: ( SocketTimeout of the socket will be 2000ms. )

public static void main(String[] args) throws IOException {
    HttpGet httpGet = new HttpGet("https://www.google.com");

httpGet.setConfig(RequestConfig.custom().setConnectTimeout(2000).build());

    CloseableHttpClient httpclient = HttpClients.createDefault();
    CloseableHttpResponse response = httpclient.execute(httpGet);
    try {
        System.out.println(EntityUtils.toString(response.getEntity()));
    } finally {
        response.close();
    }
}

Commit history:
https://github.com/apache/httpcomponents-client/commit/d954cd287dfcdad8f153e61181e20d253175ca8c
Issue before:
https://issues.apache.org/jira/browse/HTTPCLIENT-1589

Re: Issue about socketTimeout overriden during https handshake

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2018-12-28 at 14:27 +0800, 陈飞 wrote:
> Before handshake during https request, if connectTimeout is set
> alone,
> without socketTimeout, SSLConnectionSocketFactory#connectSocket will
> override socketTimeout with connectTimeout and never change back,
> anyone
> know why? is it a flaw or feature?
> 

What would be your expectation? To have the socket timeout set back to
0? Does this make sense? One can overwrite the default socket timeout
with RequestConfig once the connection has been fully established.

Oleg

> HttpClient version: 4.5.3
> 
> <dependency>
>     <groupId>org.apache.httpcomponents</groupId>
>     <artifactId>httpclient</artifactId>
>     <version>4.5.3</version>
> </dependency>
> 
> Example: ( SocketTimeout of the socket will be 2000ms. )
> 
> public static void main(String[] args) throws IOException {
>     HttpGet httpGet = new HttpGet("https://www.google.com");
> 
> httpGet.setConfig(RequestConfig.custom().setConnectTimeout(2000).buil
> d());
> 
>     CloseableHttpClient httpclient = HttpClients.createDefault();
>     CloseableHttpResponse response = httpclient.execute(httpGet);
>     try {
>         System.out.println(EntityUtils.toString(response.getEntity())
> );
>     } finally {
>         response.close();
>     }
> }
> 
> Commit history:
> 
https://github.com/apache/httpcomponents-client/commit/d954cd287dfcdad8f153e61181e20d253175ca8c
> Issue before:
> https://issues.apache.org/jira/browse/HTTPCLIENT-1589


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org