Return-Path: Delivered-To: apmail-jakarta-httpclient-commits-archive@www.apache.org Received: (qmail 622 invoked from network); 10 Aug 2005 18:37:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Aug 2005 18:37:28 -0000 Received: (qmail 46792 invoked by uid 500); 10 Aug 2005 18:37:28 -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 46779 invoked by uid 500); 10 Aug 2005 18:37:27 -0000 Delivered-To: apmail-jakarta-httpclient-cvs@jakarta.apache.org Received: (qmail 46776 invoked by uid 99); 10 Aug 2005 18:37:27 -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 [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 10 Aug 2005 11:37:27 -0700 Received: (qmail 614 invoked by uid 65534); 10 Aug 2005 18:37:27 -0000 Message-ID: <20050810183727.613.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r231292 - in /jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl: DefaultHttpClientConnection.java DefaultResponseStrategy.java ResponseStrategy.java Date: Wed, 10 Aug 2005 18:37:26 -0000 To: httpclient-cvs@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: olegk Date: Wed Aug 10 11:37:20 2005 New Revision: 231292 URL: http://svn.apache.org/viewcvs?rev=231292&view=rev Log: Added ResponseStrategy interface and its default impl Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java (with props) jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java (with props) Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java?rev=231292&r1=231291&r2=231292&view=diff ============================================================================== --- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java (original) +++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java Wed Aug 10 11:37:20 2005 @@ -205,7 +205,7 @@ // flush the headers this.datatransmitter.flush(); if (this.datareceiver.isDataAvailable(WAIT_FOR_CONTINUE_MS)) { - HttpResponse response = readResponse(request.getParams()); + HttpResponse response = readResponse(request); int status = response.getStatusLine().getStatusCode(); if (status < 200) { if (status != HttpStatus.SC_CONTINUE) { @@ -240,12 +240,11 @@ } assertOpen(); - HttpParams params = request.getParams(); // reset the data receiver - this.datareceiver.reset(params); + this.datareceiver.reset(request.getParams()); for (;;) { - HttpResponse response = readResponse(params); + HttpResponse response = readResponse(request); int statuscode = response.getStatusLine().getStatusCode(); if (statuscode >= 200) { return response; @@ -256,12 +255,13 @@ } } - protected HttpResponse readResponse(final HttpParams params) + protected HttpResponse readResponse(final HttpRequest request) throws HttpException, IOException { - this.datareceiver.reset(params); - HttpMutableResponse response = readResponseStatusLine(params); + this.datareceiver.reset(request.getParams()); + HttpMutableResponse response = readResponseStatusLine(request.getParams()); readResponseHeaders(response); - if (canResponseHaveBody(response)) { + ResponseStrategy responsestrategy = new DefaultResponseStrategy(); + if (responsestrategy.canHaveEntity(request, response)) { readResponseBody(response); } return response; Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java?rev=231292&view=auto ============================================================================== --- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java (added) +++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java Wed Aug 10 11:37:20 2005 @@ -0,0 +1,76 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * 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 implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * 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.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @version $Revision$ + * + * @since 4.0 + */ +public class DefaultResponseStrategy implements ResponseStrategy { + + private static final String HEAD_METHOD = "HEAD"; + + public DefaultResponseStrategy() { + super(); + } + + public boolean canHaveEntity(final HttpRequest request, final HttpResponse response) { + if (request == null) { + throw new IllegalArgumentException("HTTP request may not be null"); + } + if (response == null) { + throw new IllegalArgumentException("HTTP response may not be null"); + } + String method = request.getRequestLine().getMethod(); + if (HEAD_METHOD.equalsIgnoreCase(method)) { + return false; + } + int status = response.getStatusLine().getStatusCode(); + if (status < HttpStatus.SC_OK) { + return false; + } + if (status == HttpStatus.SC_NO_CONTENT || + status == HttpStatus.SC_RESET_CONTENT || + status == HttpStatus.SC_NOT_MODIFIED) { + return false; + } + return true; + } + +} Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultResponseStrategy.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java?rev=231292&view=auto ============================================================================== --- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java (added) +++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java Wed Aug 10 11:37:20 2005 @@ -0,0 +1,48 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * 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 implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * 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.HttpRequest; +import org.apache.http.HttpResponse; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @version $Revision$ + * + * @since 4.0 + */ +public interface ResponseStrategy { + + boolean canHaveEntity(HttpRequest request, HttpResponse response); + +} Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/ResponseStrategy.java ------------------------------------------------------------------------------ svn:mime-type = text/plain