hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
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 GMT
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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @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



Mime
View raw message