mobile/android/thirdparty/ch/boye/httpclientandroidlib/params/HttpProtocolParams.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 * ====================================================================
michael@0 3 * Licensed to the Apache Software Foundation (ASF) under one
michael@0 4 * or more contributor license agreements. See the NOTICE file
michael@0 5 * distributed with this work for additional information
michael@0 6 * regarding copyright ownership. The ASF licenses this file
michael@0 7 * to you under the Apache License, Version 2.0 (the
michael@0 8 * "License"); you may not use this file except in compliance
michael@0 9 * with the License. You may obtain a copy of the License at
michael@0 10 *
michael@0 11 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 12 *
michael@0 13 * Unless required by applicable law or agreed to in writing,
michael@0 14 * software distributed under the License is distributed on an
michael@0 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0 16 * KIND, either express or implied. See the License for the
michael@0 17 * specific language governing permissions and limitations
michael@0 18 * under the License.
michael@0 19 * ====================================================================
michael@0 20 *
michael@0 21 * This software consists of voluntary contributions made by many
michael@0 22 * individuals on behalf of the Apache Software Foundation. For more
michael@0 23 * information on the Apache Software Foundation, please see
michael@0 24 * <http://www.apache.org/>.
michael@0 25 *
michael@0 26 */
michael@0 27
michael@0 28 package ch.boye.httpclientandroidlib.params;
michael@0 29
michael@0 30 import ch.boye.httpclientandroidlib.HttpVersion;
michael@0 31 import ch.boye.httpclientandroidlib.ProtocolVersion;
michael@0 32 import ch.boye.httpclientandroidlib.protocol.HTTP;
michael@0 33
michael@0 34 /**
michael@0 35 * Utility class for accessing protocol parameters in {@link HttpParams}.
michael@0 36 *
michael@0 37 * @since 4.0
michael@0 38 *
michael@0 39 * @see CoreProtocolPNames
michael@0 40 */
michael@0 41 public final class HttpProtocolParams implements CoreProtocolPNames {
michael@0 42
michael@0 43 private HttpProtocolParams() {
michael@0 44 super();
michael@0 45 }
michael@0 46
michael@0 47 /**
michael@0 48 * Obtains value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter.
michael@0 49 * If not set, defaults to <code>US-ASCII</code>.
michael@0 50 *
michael@0 51 * @param params HTTP parameters.
michael@0 52 * @return HTTP element charset.
michael@0 53 */
michael@0 54 public static String getHttpElementCharset(final HttpParams params) {
michael@0 55 if (params == null) {
michael@0 56 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 57 }
michael@0 58 String charset = (String) params.getParameter
michael@0 59 (CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
michael@0 60 if (charset == null) {
michael@0 61 charset = HTTP.DEFAULT_PROTOCOL_CHARSET;
michael@0 62 }
michael@0 63 return charset;
michael@0 64 }
michael@0 65
michael@0 66 /**
michael@0 67 * Sets value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter.
michael@0 68 *
michael@0 69 * @param params HTTP parameters.
michael@0 70 * @param charset HTTP element charset.
michael@0 71 */
michael@0 72 public static void setHttpElementCharset(final HttpParams params, final String charset) {
michael@0 73 if (params == null) {
michael@0 74 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 75 }
michael@0 76 params.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset);
michael@0 77 }
michael@0 78
michael@0 79 /**
michael@0 80 * Obtains value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter.
michael@0 81 * If not set, defaults to <code>ISO-8859-1</code>.
michael@0 82 *
michael@0 83 * @param params HTTP parameters.
michael@0 84 * @return HTTP content charset.
michael@0 85 */
michael@0 86 public static String getContentCharset(final HttpParams params) {
michael@0 87 if (params == null) {
michael@0 88 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 89 }
michael@0 90 String charset = (String) params.getParameter
michael@0 91 (CoreProtocolPNames.HTTP_CONTENT_CHARSET);
michael@0 92 if (charset == null) {
michael@0 93 charset = HTTP.DEFAULT_CONTENT_CHARSET;
michael@0 94 }
michael@0 95 return charset;
michael@0 96 }
michael@0 97
michael@0 98 /**
michael@0 99 * Sets value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter.
michael@0 100 *
michael@0 101 * @param params HTTP parameters.
michael@0 102 * @param charset HTTP content charset.
michael@0 103 */
michael@0 104 public static void setContentCharset(final HttpParams params, final String charset) {
michael@0 105 if (params == null) {
michael@0 106 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 107 }
michael@0 108 params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, charset);
michael@0 109 }
michael@0 110
michael@0 111 /**
michael@0 112 * Obtains value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter.
michael@0 113 * If not set, defaults to {@link HttpVersion#HTTP_1_1}.
michael@0 114 *
michael@0 115 * @param params HTTP parameters.
michael@0 116 * @return HTTP protocol version.
michael@0 117 */
michael@0 118 public static ProtocolVersion getVersion(final HttpParams params) {
michael@0 119 if (params == null) {
michael@0 120 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 121 }
michael@0 122 Object param = params.getParameter
michael@0 123 (CoreProtocolPNames.PROTOCOL_VERSION);
michael@0 124 if (param == null) {
michael@0 125 return HttpVersion.HTTP_1_1;
michael@0 126 }
michael@0 127 return (ProtocolVersion)param;
michael@0 128 }
michael@0 129
michael@0 130 /**
michael@0 131 * Sets value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter.
michael@0 132 *
michael@0 133 * @param params HTTP parameters.
michael@0 134 * @param version HTTP protocol version.
michael@0 135 */
michael@0 136 public static void setVersion(final HttpParams params, final ProtocolVersion version) {
michael@0 137 if (params == null) {
michael@0 138 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 139 }
michael@0 140 params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, version);
michael@0 141 }
michael@0 142
michael@0 143 /**
michael@0 144 * Obtains value of the {@link CoreProtocolPNames#USER_AGENT} parameter.
michael@0 145 * If not set, returns <code>null</code>.
michael@0 146 *
michael@0 147 * @param params HTTP parameters.
michael@0 148 * @return User agent string.
michael@0 149 */
michael@0 150 public static String getUserAgent(final HttpParams params) {
michael@0 151 if (params == null) {
michael@0 152 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 153 }
michael@0 154 return (String) params.getParameter(CoreProtocolPNames.USER_AGENT);
michael@0 155 }
michael@0 156
michael@0 157 /**
michael@0 158 * Sets value of the {@link CoreProtocolPNames#USER_AGENT} parameter.
michael@0 159 *
michael@0 160 * @param params HTTP parameters.
michael@0 161 * @param useragent User agent string.
michael@0 162 */
michael@0 163 public static void setUserAgent(final HttpParams params, final String useragent) {
michael@0 164 if (params == null) {
michael@0 165 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 166 }
michael@0 167 params.setParameter(CoreProtocolPNames.USER_AGENT, useragent);
michael@0 168 }
michael@0 169
michael@0 170 /**
michael@0 171 * Obtains value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter.
michael@0 172 * If not set, returns <code>false</code>.
michael@0 173 *
michael@0 174 * @param params HTTP parameters.
michael@0 175 * @return User agent string.
michael@0 176 */
michael@0 177 public static boolean useExpectContinue(final HttpParams params) {
michael@0 178 if (params == null) {
michael@0 179 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 180 }
michael@0 181 return params.getBooleanParameter
michael@0 182 (CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
michael@0 183 }
michael@0 184
michael@0 185 /**
michael@0 186 * Sets value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter.
michael@0 187 *
michael@0 188 * @param params HTTP parameters.
michael@0 189 * @param b expect-continue flag.
michael@0 190 */
michael@0 191 public static void setUseExpectContinue(final HttpParams params, boolean b) {
michael@0 192 if (params == null) {
michael@0 193 throw new IllegalArgumentException("HTTP parameters may not be null");
michael@0 194 }
michael@0 195 params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, b);
michael@0 196 }
michael@0 197
michael@0 198 }

mercurial