Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E3102200C4B for ; Mon, 20 Mar 2017 10:39:33 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E1DE8160B81; Mon, 20 Mar 2017 09:39:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 36E59160B76 for ; Mon, 20 Mar 2017 10:39:33 +0100 (CET) Received: (qmail 86878 invoked by uid 500); 20 Mar 2017 09:39:32 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 86869 invoked by uid 99); 20 Mar 2017 09:39:32 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Mar 2017 09:39:32 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id B41263A0597 for ; Mon, 20 Mar 2017 09:39:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Mon, 20 Mar 2017 09:39:31 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170320093931.B41263A0597@svn01-us-west.apache.org> archived-at: Mon, 20 Mar 2017 09:39:34 -0000 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;