Return-Path: Delivered-To: apmail-jakarta-httpclient-commits-archive@www.apache.org Received: (qmail 68345 invoked from network); 3 Apr 2005 16:18:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Apr 2005 16:18:24 -0000 Received: (qmail 5370 invoked by uid 500); 3 Apr 2005 16:18:24 -0000 Mailing-List: contact httpclient-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpclient-dev@jakarta.apache.org Delivered-To: mailing list httpclient-commits@jakarta.apache.org Received: (qmail 5354 invoked by uid 500); 3 Apr 2005 16:18:24 -0000 Delivered-To: apmail-jakarta-httpclient-cvs@jakarta.apache.org Received: (qmail 5351 invoked by uid 99); 3 Apr 2005 16:18:24 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 03 Apr 2005 09:18:23 -0700 Received: (qmail 68339 invoked by uid 65534); 3 Apr 2005 16:18:22 -0000 Message-ID: <20050403161822.68338.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Sun, 03 Apr 2005 16:18:22 -0000 Subject: svn commit: r159931 - in jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl: ConnectionReuseStrategy.java DefaultConnectionReuseStrategy.java To: httpclient-cvs@jakarta.apache.org From: olegk@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Sun Apr 3 09:18:20 2005 New Revision: 159931 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D159931 Log: Added ConnectionReuseStrategy interface and its default impl Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Conn= ectionReuseStrategy.java (with props) jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Defa= ultConnectionReuseStrategy.java (with props) Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/C= onnectionReuseStrategy.java URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src= /java/org/apache/http/impl/ConnectionReuseStrategy.java?view=3Dauto&rev=3D1= 59931 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Conn= ectionReuseStrategy.java (added) +++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Conn= ectionReuseStrategy.java Sun Apr 3 09:18:20 2005 @@ -0,0 +1,47 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * Copyright 1999-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.impl; + +import org.apache.http.HttpResponse; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @version $Revision$ + *=20 + * @since 4.0 + */ +public interface ConnectionReuseStrategy { + + boolean keepAlive(HttpResponse response); + =20 +} Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/ConnectionReuseStrategy.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/ConnectionReuseStrategy.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/ConnectionReuseStrategy.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/D= efaultConnectionReuseStrategy.java URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src= /java/org/apache/http/impl/DefaultConnectionReuseStrategy.java?view=3Dauto&= rev=3D159931 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Defa= ultConnectionReuseStrategy.java (added) +++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/Defa= ultConnectionReuseStrategy.java Sun Apr 3 09:18:20 2005 @@ -0,0 +1,85 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * Copyright 1999-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.impl; + +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpVersion; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @version $Revision$ + *=20 + * @since 4.0 + */ +public class DefaultConnectionReuseStrategy implements ConnectionReuseStra= tegy { + + private static final String CONN_DIRECTIVE =3D "Connection"; + private static final String CONN_CLOSE =3D "Close"; + private static final String CONN_KEEP_ALIVE =3D "Keep-Alive"; + =20 + public DefaultConnectionReuseStrategy() { + super(); + } + =20 + public boolean keepAlive(final HttpResponse response) { + if (response =3D=3D null) { + throw new IllegalArgumentException("HTTP response may not be n= ull"); + } + HttpEntity entity =3D response.getEntity(); + HttpVersion ver =3D response.getStatusLine().getHttpVersion(); + if (entity !=3D null) { + if (entity.getContentLength() < 0 && !entity.isChunked()) { + // if the content length is not known and is not chunk + // encoded, the connection cannot be reused + return false; + } + } + // Check for 'Connection' directive + Header connheader =3D response.getFirstHeader(CONN_DIRECTIVE); + if (connheader !=3D null) { + String conndirective =3D connheader.getValue();=20 + if (CONN_CLOSE.equalsIgnoreCase(conndirective)) { + return false; + } else if (CONN_KEEP_ALIVE.equalsIgnoreCase(conndirective)) { + return true; + } else { + // log unknown directive + } + } + // Resorting to protocol version default close connection policy + return ver.greaterEquals(HttpVersion.HTTP_1_1); + } + =20 +} Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/DefaultConnectionReuseStrategy.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/DefaultConnectionReuseStrategy.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/i= mpl/DefaultConnectionReuseStrategy.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain