1/*2 * ====================================================================3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 * ====================================================================20 *21 * This software consists of voluntary contributions made by many22 * individuals on behalf of the Apache Software Foundation. For more23 * information on the Apache Software Foundation, please see24 * <http://www.apache.org/>.25 *26 */2728package org.apache.http;
2930import org.apache.http.protocol.HttpContext;
3132/**33 * Interface for deciding whether a connection can be re-used for34 * subsequent requests and should be kept alive.35 * <p>36 * Implementations of this interface must be thread-safe. Access to shared37 * data must be synchronized as methods of this interface may be executed38 * from multiple threads.39 *40 * @since 4.041 */42publicinterfaceConnectionReuseStrategy {
4344/**45 * Decides whether a connection can be kept open after a request.46 * If this method returns <code>false</code>, the caller MUST47 * close the connection to correctly comply with the HTTP protocol.48 * If it returns <code>true</code>, the caller SHOULD attempt to49 * keep the connection open for reuse with another request.50 * <br/>51 * One can use the HTTP context to retrieve additional objects that52 * may be relevant for the keep-alive strategy: the actual HTTP53 * connection, the original HTTP request, target host if known,54 * number of times the connection has been reused already and so on.55 * <br/>56 * If the connection is already closed, <code>false</code> is returned.57 * The stale connection check MUST NOT be triggered by a58 * connection reuse strategy.59 *60 * @param response61 * The last response received over that connection.62 * @param context the context in which the connection is being63 * used.64 *65 * @return <code>true</code> if the connection is allowed to be reused, or66 * <code>false</code> if it MUST NOT be reused67 */68boolean keepAlive(HttpResponse response, HttpContext context);
6970 }