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 2017/03/20 09:39:31 UTC

svn commit: r1787697 - in /httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java

Author: olegk
Date: Mon Mar 20 09:39:31 2017
New Revision: 1787697

URL: http://svn.apache.org/viewvc?rev=1787697&view=rev
Log:
Better handling of missing content-type header in OPTIONS with entity

Modified:
    httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java
    httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java

Modified: httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java?rev=1787697&r1=1787696&r2=1787697&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java (original)
+++ httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java Mon Mar 20 09:39:31 2017
@@ -32,7 +32,9 @@ import java.util.List;
 
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHeaders;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -43,8 +45,8 @@ import org.apache.http.annotation.Thread
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.client.methods.HttpRequestWrapper;
-import org.apache.http.entity.AbstractHttpEntity;
 import org.apache.http.entity.ContentType;
+import org.apache.http.entity.HttpEntityWrapper;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.message.BasicStatusLine;
@@ -193,9 +195,17 @@ class RequestProtocolCompliance {
     }
 
     private void addContentTypeHeaderIfMissing(final HttpEntityEnclosingRequest request) {
-        if (request.getEntity().getContentType() == null) {
-            ((AbstractHttpEntity) request.getEntity()).setContentType(
-                    ContentType.APPLICATION_OCTET_STREAM.getMimeType());
+        final HttpEntity entity = request.getEntity();
+        if (entity != null && entity.getContentType() == null) {
+            final HttpEntityWrapper entityWrapper = new HttpEntityWrapper(entity) {
+
+                @Override
+                public Header getContentType() {
+                    return new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_OCTET_STREAM.getMimeType());
+                }
+
+            };
+            request.setEntity(entityWrapper);
         }
     }
 

Modified: httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java?rev=1787697&r1=1787696&r2=1787697&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java (original)
+++ httpcomponents/httpclient/branches/4.6.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolDeviations.java Mon Mar 20 09:39:31 2017
@@ -42,9 +42,9 @@ import org.apache.http.client.methods.Cl
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.client.utils.DateUtils;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.client.utils.DateUtils;
 import org.apache.http.impl.execchain.ClientExecChain;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
 import org.apache.http.message.BasicHttpRequest;