You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2006/03/14 21:04:01 UTC

svn commit: r385866 - in /jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol: RequestContent.java ResponseContent.java

Author: olegk
Date: Tue Mar 14 12:03:59 2006
New Revision: 385866

URL: http://svn.apache.org/viewcvs?rev=385866&view=rev
Log:
Changed RequestConent and ResponseContent to throw a protocol exception of Content-Length or Transfer-Encoding headers are already present

Modified:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/RequestContent.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/ResponseContent.java

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/RequestContent.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/RequestContent.java?rev=385866&r1=385865&r2=385866&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/RequestContent.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/RequestContent.java Tue Mar 14 12:03:59 2006
@@ -61,6 +61,12 @@
             throw new IllegalArgumentException("HTTP request may not be null");
         }
         if (request instanceof HttpEntityEnclosingRequest) {
+            if (request.containsHeader(HTTP.TRANSFER_ENCODING)) {
+                throw new ProtocolException("Transfer-encoding header already present");
+            }
+            if (request.containsHeader(HTTP.CONTENT_LEN)) {
+                throw new ProtocolException("Content-Length header already present");
+            }
             HttpVersion ver = request.getRequestLine().getHttpVersion();
             HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
             if (entity == null) {
@@ -73,17 +79,19 @@
                     throw new ProtocolException(
                             "Chunked transfer encoding not allowed for " + ver);
                 }
-                request.setHeader(
-                        new Header(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING));
-                request.removeHeaders(HTTP.CONTENT_LEN);
+                request.addHeader(new Header(HTTP.TRANSFER_ENCODING, 
+                        HTTP.CHUNK_CODING));
             } else {
-                request.setHeader(new Header(HTTP.CONTENT_LEN, 
+                request.addHeader(new Header(HTTP.CONTENT_LEN, 
                         Long.toString(entity.getContentLength())));
-                request.removeHeaders(HTTP.TRANSFER_ENCODING);
             }
             // Specify a content type if known
             if (entity.getContentType() != null) {
                 request.setHeader(entity.getContentType()); 
+            }
+            // Specify a content encoding if known
+            if (entity.getContentEncoding() != null) {
+                request.setHeader(entity.getContentEncoding()); 
             }
         }
     }

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/ResponseContent.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/ResponseContent.java?rev=385866&r1=385865&r2=385866&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/ResponseContent.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/ResponseContent.java Tue Mar 14 12:03:59 2006
@@ -37,6 +37,7 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.HttpVersion;
+import org.apache.http.ProtocolException;
 
 /**
  * A response interceptor that sets up entity-related headers.
@@ -59,17 +60,22 @@
         if (response == null) {
             throw new IllegalArgumentException("HTTP request may not be null");
         }
+        if (response.containsHeader(HTTP.TRANSFER_ENCODING)) {
+            throw new ProtocolException("Transfer-encoding header already present");
+        }
+        if (response.containsHeader(HTTP.CONTENT_LEN)) {
+            throw new ProtocolException("Content-Length header already present");
+        }
         HttpVersion ver = response.getStatusLine().getHttpVersion();
         HttpEntity entity = response.getEntity();
         if (entity != null) {
             long len = entity.getContentLength();
             if (entity.isChunked() && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
-                response.setHeader(new Header(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING));
-                response.removeHeaders(HTTP.CONTENT_LEN);
+                response.addHeader(new Header(HTTP.TRANSFER_ENCODING, 
+                        HTTP.CHUNK_CODING));
             } else if (len >= 0) {
-                response.setHeader(new Header(HTTP.CONTENT_LEN, 
+                response.addHeader(new Header(HTTP.CONTENT_LEN, 
                         Long.toString(entity.getContentLength())));
-                response.removeHeaders(HTTP.TRANSFER_ENCODING);
             }
             // Specify a content type if known
             if (entity.getContentType() != null) {