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 org.apache.http.impl;
29
30 import java.io.IOException;
31 import java.net.Socket;
32
33 import org.apache.http.annotation.NotThreadSafe;
34 import org.apache.http.params.HttpConnectionParams;
35 import org.apache.http.params.HttpParams;
36
37 /**
38 * Default implementation of a client-side HTTP connection.
39 * <p>
40 * The following parameters can be used to customize the behavior of this
41 * class:
42 * <ul>
43 * <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
44 * <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}</li>
45 * <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
46 * <li>{@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}</li>
47 * <li>{@link org.apache.http.params.CoreConnectionPNames#SO_KEEPALIVE}</li>
48 * <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
49 * <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
50 * <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
51 * <li>{@link org.apache.http.params.CoreConnectionPNames#MIN_CHUNK_LIMIT}</li>
52 * </ul>
53 *
54 * @since 4.0
55 */
56 @NotThreadSafe
57 public class DefaultHttpClientConnection extends SocketHttpClientConnection {
58
59 public DefaultHttpClientConnection() {
60 super();
61 }
62
63 @Override
64 public void bind(
65 final Socket socket,
66 final HttpParams params) throws IOException {
67 if (socket == null) {
68 throw new IllegalArgumentException("Socket may not be null");
69 }
70 if (params == null) {
71 throw new IllegalArgumentException("HTTP parameters may not be null");
72 }
73 assertNotOpen();
74 socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
75 socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
76 socket.setKeepAlive(HttpConnectionParams.getSoKeepalive(params));
77
78 int linger = HttpConnectionParams.getLinger(params);
79 if (linger >= 0) {
80 socket.setSoLinger(linger > 0, linger);
81 }
82 super.bind(socket, params);
83 }
84
85 }