1 /*
2  * ====================================================================
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  * ====================================================================
20  *
21  * This software consists of voluntary contributions made by many
22  * individuals on behalf of the Apache Software Foundation.  For more
23  * information on the Apache Software Foundation, please see
24  * <http://www.apache.org/>.
25  *
26  */
27 
28 package ch.boye.httpclientandroidlib.client.params;
29 
30 import java.net.InetAddress;
31 import java.util.Collection;
32 
33 import ch.boye.httpclientandroidlib.HttpHost;
34 import ch.boye.httpclientandroidlib.auth.params.AuthPNames;
35 import ch.boye.httpclientandroidlib.client.config.RequestConfig;
36 import ch.boye.httpclientandroidlib.conn.params.ConnRoutePNames;
37 import ch.boye.httpclientandroidlib.params.CoreConnectionPNames;
38 import ch.boye.httpclientandroidlib.params.CoreProtocolPNames;
39 import ch.boye.httpclientandroidlib.params.HttpParams;
40 
41 /**
42  * @deprecated (4.3) provided for compatibility with {@link HttpParams}. Do not use.
43  *
44  * @since 4.3
45  */
46 @Deprecated
47 public final class HttpClientParamConfig {
48 
HttpClientParamConfig()49     private HttpClientParamConfig() {
50     }
51 
52     @SuppressWarnings("unchecked")
getRequestConfig(final HttpParams params)53     public static RequestConfig getRequestConfig(final HttpParams params) {
54         return RequestConfig.custom()
55                 .setSocketTimeout(params.getIntParameter(
56                         CoreConnectionPNames.SO_TIMEOUT, 0))
57                 .setStaleConnectionCheckEnabled(params.getBooleanParameter(
58                         CoreConnectionPNames.STALE_CONNECTION_CHECK, true))
59                 .setConnectTimeout(params.getIntParameter(
60                         CoreConnectionPNames.CONNECTION_TIMEOUT, 0))
61                 .setExpectContinueEnabled(params.getBooleanParameter(
62                         CoreProtocolPNames.USE_EXPECT_CONTINUE, false))
63                 .setProxy((HttpHost) params.getParameter(
64                         ConnRoutePNames.DEFAULT_PROXY))
65                 .setLocalAddress((InetAddress) params.getParameter(
66                         ConnRoutePNames.LOCAL_ADDRESS))
67                 .setProxyPreferredAuthSchemes((Collection<String>) params.getParameter(
68                         AuthPNames.PROXY_AUTH_PREF))
69                 .setTargetPreferredAuthSchemes((Collection<String>) params.getParameter(
70                         AuthPNames.TARGET_AUTH_PREF))
71                 .setAuthenticationEnabled(params.getBooleanParameter(
72                         ClientPNames.HANDLE_AUTHENTICATION, true))
73                 .setCircularRedirectsAllowed(params.getBooleanParameter(
74                         ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false))
75                 .setConnectionRequestTimeout((int) params.getLongParameter(
76                         ClientPNames.CONN_MANAGER_TIMEOUT, 0))
77                 .setCookieSpec((String) params.getParameter(
78                         ClientPNames.COOKIE_POLICY))
79                 .setMaxRedirects(params.getIntParameter(
80                         ClientPNames.MAX_REDIRECTS, 50))
81                 .setRedirectsEnabled(params.getBooleanParameter(
82                         ClientPNames.HANDLE_REDIRECTS, true))
83                 .setRelativeRedirectsAllowed(!params.getBooleanParameter(
84                         ClientPNames.REJECT_RELATIVE_REDIRECT, false))
85                 .build();
86     }
87 
88 }
89