michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.impl.client; michael@0: michael@0: import ch.boye.httpclientandroidlib.HttpVersion; michael@0: import ch.boye.httpclientandroidlib.annotation.ThreadSafe; michael@0: import ch.boye.httpclientandroidlib.client.HttpClient; michael@0: import ch.boye.httpclientandroidlib.client.protocol.RequestAddCookies; michael@0: import ch.boye.httpclientandroidlib.client.protocol.RequestAuthCache; michael@0: import ch.boye.httpclientandroidlib.client.protocol.RequestClientConnControl; michael@0: import ch.boye.httpclientandroidlib.client.protocol.RequestDefaultHeaders; michael@0: import ch.boye.httpclientandroidlib.client.protocol.RequestProxyAuthentication; michael@0: import ch.boye.httpclientandroidlib.client.protocol.RequestTargetAuthentication; michael@0: import ch.boye.httpclientandroidlib.client.protocol.ResponseAuthCache; michael@0: import ch.boye.httpclientandroidlib.client.protocol.ResponseProcessCookies; michael@0: import ch.boye.httpclientandroidlib.conn.ClientConnectionManager; michael@0: import ch.boye.httpclientandroidlib.params.CoreConnectionPNames; michael@0: import ch.boye.httpclientandroidlib.params.CoreProtocolPNames; michael@0: import ch.boye.httpclientandroidlib.params.HttpConnectionParams; michael@0: import ch.boye.httpclientandroidlib.params.HttpParams; michael@0: import ch.boye.httpclientandroidlib.params.HttpProtocolParams; michael@0: import ch.boye.httpclientandroidlib.params.SyncBasicHttpParams; michael@0: import ch.boye.httpclientandroidlib.protocol.BasicHttpProcessor; michael@0: import ch.boye.httpclientandroidlib.protocol.HTTP; michael@0: import ch.boye.httpclientandroidlib.protocol.RequestContent; michael@0: import ch.boye.httpclientandroidlib.protocol.RequestExpectContinue; michael@0: import ch.boye.httpclientandroidlib.protocol.RequestTargetHost; michael@0: import ch.boye.httpclientandroidlib.protocol.RequestUserAgent; michael@0: import ch.boye.httpclientandroidlib.util.VersionInfo; michael@0: michael@0: /** michael@0: * Default implementation of {@link HttpClient} pre-configured for most common use scenarios. michael@0: *

michael@0: * This class creates the following chain of protocol interceptors per default: michael@0: *

michael@0: *

michael@0: * This class sets up the following parameters if not explicitly set: michael@0: *

michael@0: *

michael@0: * The following parameters can be used to customize the behavior of this michael@0: * class: michael@0: *

michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: @ThreadSafe michael@0: public class DefaultHttpClient extends AbstractHttpClient { michael@0: michael@0: /** michael@0: * Creates a new HTTP client from parameters and a connection manager. michael@0: * michael@0: * @param params the parameters michael@0: * @param conman the connection manager michael@0: */ michael@0: public DefaultHttpClient( michael@0: final ClientConnectionManager conman, michael@0: final HttpParams params) { michael@0: super(conman, params); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * @since 4.1 michael@0: */ michael@0: public DefaultHttpClient( michael@0: final ClientConnectionManager conman) { michael@0: super(conman, null); michael@0: } michael@0: michael@0: michael@0: public DefaultHttpClient(final HttpParams params) { michael@0: super(null, params); michael@0: } michael@0: michael@0: michael@0: public DefaultHttpClient() { michael@0: super(null, null); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Creates the default set of HttpParams by invoking {@link DefaultHttpClient#setDefaultHttpParams(HttpParams)} michael@0: * michael@0: * @return a new instance of {@link SyncBasicHttpParams} with the defaults applied to it. michael@0: */ michael@0: @Override michael@0: protected HttpParams createHttpParams() { michael@0: HttpParams params = new SyncBasicHttpParams(); michael@0: setDefaultHttpParams(params); michael@0: return params; michael@0: } michael@0: michael@0: /** michael@0: * Saves the default set of HttpParams in the provided parameter. michael@0: * These are: michael@0: * michael@0: */ michael@0: public static void setDefaultHttpParams(HttpParams params) { michael@0: HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); michael@0: HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); michael@0: HttpConnectionParams.setTcpNoDelay(params, true); michael@0: HttpConnectionParams.setSocketBufferSize(params, 8192); michael@0: michael@0: // determine the release version from packaged version info michael@0: final VersionInfo vi = VersionInfo.loadVersionInfo michael@0: ("ch.boye.httpclientandroidlib.client", DefaultHttpClient.class.getClassLoader()); michael@0: final String release = (vi != null) ? michael@0: vi.getRelease() : VersionInfo.UNAVAILABLE; michael@0: HttpProtocolParams.setUserAgent(params, michael@0: "Apache-HttpClient/" + release + " (java 1.5)"); michael@0: } michael@0: michael@0: michael@0: @Override michael@0: protected BasicHttpProcessor createHttpProcessor() { michael@0: BasicHttpProcessor httpproc = new BasicHttpProcessor(); michael@0: httpproc.addInterceptor(new RequestDefaultHeaders()); michael@0: // Required protocol interceptors michael@0: httpproc.addInterceptor(new RequestContent()); michael@0: httpproc.addInterceptor(new RequestTargetHost()); michael@0: // Recommended protocol interceptors michael@0: httpproc.addInterceptor(new RequestClientConnControl()); michael@0: httpproc.addInterceptor(new RequestUserAgent()); michael@0: httpproc.addInterceptor(new RequestExpectContinue()); michael@0: // HTTP state management interceptors michael@0: httpproc.addInterceptor(new RequestAddCookies()); michael@0: httpproc.addInterceptor(new ResponseProcessCookies()); michael@0: // HTTP authentication interceptors michael@0: httpproc.addInterceptor(new RequestAuthCache()); michael@0: httpproc.addInterceptor(new ResponseAuthCache()); michael@0: httpproc.addInterceptor(new RequestTargetAuthentication()); michael@0: httpproc.addInterceptor(new RequestProxyAuthentication()); michael@0: return httpproc; michael@0: } michael@0: michael@0: }