hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r231505 - in /jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol: RequestConnControl.java RequestContent.java RequestExpectContinue.java ResponseContent.java
Date Thu, 11 Aug 2005 19:24:38 GMT
Author: olegk
Date: Thu Aug 11 12:24:33 2005
New Revision: 231505

URL: http://svn.apache.org/viewcvs?rev=231505&view=rev
Log:
Fixed ResponseContent interceptor

Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestConnControl.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestContent.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestExpectContinue.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestConnControl.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestConnControl.java?rev=231505&r1=231504&r2=231505&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestConnControl.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestConnControl.java
Thu Aug 11 12:24:33 2005
@@ -48,6 +48,8 @@
 public class RequestConnControl implements HttpRequestInterceptor {
 
     private static final String CONN_DIRECTIVE = "Connection";
+
+    private static final String CONN_KEEPALIVE = "Keep-Alive";
     
     public RequestConnControl() {
         super();
@@ -61,7 +63,7 @@
         if (!request.containsHeader(CONN_DIRECTIVE)) {
             // Default policy is to keep connection alive
             // whenever possible
-            request.addHeader(new Header(CONN_DIRECTIVE, "Keep-Alive", true));
+            request.addHeader(new Header(CONN_DIRECTIVE, CONN_KEEPALIVE, true));
         }
     }
     

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestContent.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestContent.java?rev=231505&r1=231504&r2=231505&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestContent.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestContent.java
Thu Aug 11 12:24:33 2005
@@ -55,6 +55,8 @@
     private static final String CONTENT_LEN  = "Content-Length";
     private static final String CONTENT_TYPE = "Content-Type";
     
+    private static final String CHUNK_CODING = "chunked";
+    
     public RequestContent() {
         super();
     }
@@ -73,7 +75,7 @@
                     throw new ProtocolException(
                             "Chunked transfer encoding not allowed for " + ver);
                 }
-                request.setHeader(new Header(TRANSFER_ENC, "chunked", true));
+                request.setHeader(new Header(TRANSFER_ENC, CHUNK_CODING, true));
                 request.removeHeaders(CONTENT_LEN);
             } else {
                 request.setHeader(new Header(CONTENT_LEN, 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestExpectContinue.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestExpectContinue.java?rev=231505&r1=231504&r2=231505&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestExpectContinue.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/RequestExpectContinue.java
Thu Aug 11 12:24:33 2005
@@ -53,6 +53,8 @@
 
     private static final String EXPECT_DIRECTIVE = "Expect";
     
+    private static final String CONTINUE = "100-Continue";
+    
     public RequestExpectContinue() {
         super();
     }
@@ -69,7 +71,7 @@
                 HttpVersion ver = request.getRequestLine().getHttpVersion();
                 if (HttpProtocolParams.useExpectContinue(request.getParams()) 
                         && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
-                    request.addHeader(new Header(EXPECT_DIRECTIVE, "100-Continue", true));
+                    request.addHeader(new Header(EXPECT_DIRECTIVE, CONTINUE, true));
                 }
             }
         }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java?rev=231505&r1=231504&r2=231505&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java
Thu Aug 11 12:24:33 2005
@@ -37,7 +37,6 @@
 import org.apache.http.HttpMutableResponse;
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolException;
 
 /**
  * <p>
@@ -53,6 +52,11 @@
     private static final String TRANSFER_ENC = "Transfer-Encoding";
     private static final String CONTENT_LEN  = "Content-Length";
     private static final String CONTENT_TYPE = "Content-Type";
+    private static final String CONTENT_ENC = "Content-Encoding";
+    private static final String CONN_DIRECTIVE = "Connection";
+
+    private static final String CHUNK_CODING = "chunked";
+    private static final String CONN_CLOSE = "close";
     
     public ResponseContent() {
         super();
@@ -65,22 +69,26 @@
         }
         HttpVersion ver = response.getStatusLine().getHttpVersion();
         HttpEntity entity = response.getEntity();
-        // Must specify a transfer encoding or a content length 
-        if (entity.isChunked() || entity.getContentLength() < 0) {
-            if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
-                throw new ProtocolException(
-                        "Chunked transfer encoding not allowed for " + ver);
+        if (entity != null) {
+            long len = entity.getContentLength();
+            if (entity.isChunked() && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
+                response.setHeader(new Header(TRANSFER_ENC, CHUNK_CODING, true));
+                response.removeHeaders(CONTENT_LEN);
+            } else if (len >= 0) {
+                response.setHeader(new Header(CONTENT_LEN, 
+                        Long.toString(entity.getContentLength()), true));
+                response.removeHeaders(TRANSFER_ENC);
+            } else {
+                response.setHeader(new Header(CONN_DIRECTIVE, CONN_CLOSE, true));
+            }
+            // Specify a content type if known
+            if (entity.getContentType() != null) {
+                response.setHeader(new Header(CONTENT_TYPE, entity.getContentType(), true));

+            }
+            // Specify a content encoding if known
+            if (entity.getContentEncoding() != null) {
+                response.setHeader(new Header(CONTENT_ENC, entity.getContentEncoding(), true));

             }
-            response.setHeader(new Header(TRANSFER_ENC, "chunked", true));
-            response.removeHeaders(CONTENT_LEN);
-        } else {
-            response.setHeader(new Header(CONTENT_LEN, 
-                    Long.toString(entity.getContentLength()), true));
-            response.removeHeaders(TRANSFER_ENC);
-        }
-        // Specify a content type if known
-        if (entity.getContentType() != null) {
-            response.setHeader(new Header(CONTENT_TYPE, entity.getContentType(), true));

         }
     }
     



Mime
View raw message