1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/params/HttpProtocolParams.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,198 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.params; 1.32 + 1.33 +import ch.boye.httpclientandroidlib.HttpVersion; 1.34 +import ch.boye.httpclientandroidlib.ProtocolVersion; 1.35 +import ch.boye.httpclientandroidlib.protocol.HTTP; 1.36 + 1.37 +/** 1.38 + * Utility class for accessing protocol parameters in {@link HttpParams}. 1.39 + * 1.40 + * @since 4.0 1.41 + * 1.42 + * @see CoreProtocolPNames 1.43 + */ 1.44 +public final class HttpProtocolParams implements CoreProtocolPNames { 1.45 + 1.46 + private HttpProtocolParams() { 1.47 + super(); 1.48 + } 1.49 + 1.50 + /** 1.51 + * Obtains value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter. 1.52 + * If not set, defaults to <code>US-ASCII</code>. 1.53 + * 1.54 + * @param params HTTP parameters. 1.55 + * @return HTTP element charset. 1.56 + */ 1.57 + public static String getHttpElementCharset(final HttpParams params) { 1.58 + if (params == null) { 1.59 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.60 + } 1.61 + String charset = (String) params.getParameter 1.62 + (CoreProtocolPNames.HTTP_ELEMENT_CHARSET); 1.63 + if (charset == null) { 1.64 + charset = HTTP.DEFAULT_PROTOCOL_CHARSET; 1.65 + } 1.66 + return charset; 1.67 + } 1.68 + 1.69 + /** 1.70 + * Sets value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter. 1.71 + * 1.72 + * @param params HTTP parameters. 1.73 + * @param charset HTTP element charset. 1.74 + */ 1.75 + public static void setHttpElementCharset(final HttpParams params, final String charset) { 1.76 + if (params == null) { 1.77 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.78 + } 1.79 + params.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset); 1.80 + } 1.81 + 1.82 + /** 1.83 + * Obtains value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter. 1.84 + * If not set, defaults to <code>ISO-8859-1</code>. 1.85 + * 1.86 + * @param params HTTP parameters. 1.87 + * @return HTTP content charset. 1.88 + */ 1.89 + public static String getContentCharset(final HttpParams params) { 1.90 + if (params == null) { 1.91 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.92 + } 1.93 + String charset = (String) params.getParameter 1.94 + (CoreProtocolPNames.HTTP_CONTENT_CHARSET); 1.95 + if (charset == null) { 1.96 + charset = HTTP.DEFAULT_CONTENT_CHARSET; 1.97 + } 1.98 + return charset; 1.99 + } 1.100 + 1.101 + /** 1.102 + * Sets value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter. 1.103 + * 1.104 + * @param params HTTP parameters. 1.105 + * @param charset HTTP content charset. 1.106 + */ 1.107 + public static void setContentCharset(final HttpParams params, final String charset) { 1.108 + if (params == null) { 1.109 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.110 + } 1.111 + params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, charset); 1.112 + } 1.113 + 1.114 + /** 1.115 + * Obtains value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter. 1.116 + * If not set, defaults to {@link HttpVersion#HTTP_1_1}. 1.117 + * 1.118 + * @param params HTTP parameters. 1.119 + * @return HTTP protocol version. 1.120 + */ 1.121 + public static ProtocolVersion getVersion(final HttpParams params) { 1.122 + if (params == null) { 1.123 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.124 + } 1.125 + Object param = params.getParameter 1.126 + (CoreProtocolPNames.PROTOCOL_VERSION); 1.127 + if (param == null) { 1.128 + return HttpVersion.HTTP_1_1; 1.129 + } 1.130 + return (ProtocolVersion)param; 1.131 + } 1.132 + 1.133 + /** 1.134 + * Sets value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter. 1.135 + * 1.136 + * @param params HTTP parameters. 1.137 + * @param version HTTP protocol version. 1.138 + */ 1.139 + public static void setVersion(final HttpParams params, final ProtocolVersion version) { 1.140 + if (params == null) { 1.141 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.142 + } 1.143 + params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, version); 1.144 + } 1.145 + 1.146 + /** 1.147 + * Obtains value of the {@link CoreProtocolPNames#USER_AGENT} parameter. 1.148 + * If not set, returns <code>null</code>. 1.149 + * 1.150 + * @param params HTTP parameters. 1.151 + * @return User agent string. 1.152 + */ 1.153 + public static String getUserAgent(final HttpParams params) { 1.154 + if (params == null) { 1.155 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.156 + } 1.157 + return (String) params.getParameter(CoreProtocolPNames.USER_AGENT); 1.158 + } 1.159 + 1.160 + /** 1.161 + * Sets value of the {@link CoreProtocolPNames#USER_AGENT} parameter. 1.162 + * 1.163 + * @param params HTTP parameters. 1.164 + * @param useragent User agent string. 1.165 + */ 1.166 + public static void setUserAgent(final HttpParams params, final String useragent) { 1.167 + if (params == null) { 1.168 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.169 + } 1.170 + params.setParameter(CoreProtocolPNames.USER_AGENT, useragent); 1.171 + } 1.172 + 1.173 + /** 1.174 + * Obtains value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter. 1.175 + * If not set, returns <code>false</code>. 1.176 + * 1.177 + * @param params HTTP parameters. 1.178 + * @return User agent string. 1.179 + */ 1.180 + public static boolean useExpectContinue(final HttpParams params) { 1.181 + if (params == null) { 1.182 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.183 + } 1.184 + return params.getBooleanParameter 1.185 + (CoreProtocolPNames.USE_EXPECT_CONTINUE, false); 1.186 + } 1.187 + 1.188 + /** 1.189 + * Sets value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter. 1.190 + * 1.191 + * @param params HTTP parameters. 1.192 + * @param b expect-continue flag. 1.193 + */ 1.194 + public static void setUseExpectContinue(final HttpParams params, boolean b) { 1.195 + if (params == null) { 1.196 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.197 + } 1.198 + params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, b); 1.199 + } 1.200 + 1.201 +}