Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A8B3018896 for ; Thu, 13 Aug 2015 12:07:46 +0000 (UTC) Received: (qmail 82541 invoked by uid 500); 13 Aug 2015 12:07:46 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 82477 invoked by uid 500); 13 Aug 2015 12:07:46 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 82456 invoked by uid 99); 13 Aug 2015 12:07:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Aug 2015 12:07:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 48CC1E6833; Thu, 13 Aug 2015 12:07:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6528] Adding a property for users to disable sending CT with empty requests Date: Thu, 13 Aug 2015 12:07:46 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/master 6ba43377b -> 610791147 [CXF-6528] Adding a property for users to disable sending CT with empty requests Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/61079114 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/61079114 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/61079114 Branch: refs/heads/master Commit: 61079114761b1a4a9898902ed07e5203bf5dd31c Parents: 6ba4337 Author: Sergey Beryozkin Authored: Thu Aug 13 13:07:26 2015 +0100 Committer: Sergey Beryozkin Committed: Thu Aug 13 13:07:26 2015 +0100 ---------------------------------------------------------------------- .../org/apache/cxf/transport/http/Headers.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/61079114/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java ---------------------------------------------------------------------- diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java index 3afb67a..3a4f7af 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java @@ -67,7 +67,7 @@ public class Headers { public static final String HTTP_HEADERS_SETCOOKIE = "Set-Cookie"; public static final String HTTP_HEADERS_LINK = "Link"; public static final String EMPTY_REQUEST_PROPERTY = "org.apache.cxf.empty.request"; - private static final String USE_ASYNC_PROPERTY = "use.async.http.conduit"; + private static final String SET_EMPTY_REQUEST_CT_PROPERTY = "set.content.type.for.empty.request"; private static final TimeZone TIME_ZONE_GMT = TimeZone.getTimeZone("GMT"); private static final Logger LOG = LogUtils.getL7dLogger(Headers.class); @@ -297,14 +297,21 @@ public class Headers { * @throws IOException */ public void setProtocolHeadersInConnection(HttpURLConnection connection) throws IOException { + // If no Content-Type is set for empty requests then HttpUrlConnection: + // - sets a form Content-Type for empty POST + // - replaces custom Accept value with */* if HTTP proxy is used + + boolean dropContentType = false; boolean emptyRequest = PropertyUtils.isTrue(message.get(EMPTY_REQUEST_PROPERTY)); - // HttpUrlConnection sets a form Content-Type and completely loses custom Accept - // if HTTP proxies are used if no Content-Type is set for empty requests - boolean asyncConduitUsed = PropertyUtils.isTrue(message.get(USE_ASYNC_PROPERTY)); - if (!asyncConduitUsed || !emptyRequest) { + if (emptyRequest) { + // drop only if a user explicitly requested it by setting the property to false + dropContentType = !MessageUtils.getContextualBoolean(message, SET_EMPTY_REQUEST_CT_PROPERTY, true); + } + if (!dropContentType) { String ct = emptyRequest ? "*/*" : determineContentType(); connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, ct); } + transferProtocolHeadersToURLConnection(connection); logProtocolHeaders(Level.FINE);