You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/02/29 12:20:25 UTC

cxf git commit: [CXF-6805] Updating Headers not to expect the client GET code to set an empty request property if they don't need Content-Type

Repository: cxf
Updated Branches:
  refs/heads/master 3132adfe2 -> a669400fc


[CXF-6805] Updating Headers not to expect the client GET code to set an empty request property if they don't need Content-Type


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a669400f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a669400f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a669400f

Branch: refs/heads/master
Commit: a669400fc5001db5e533514fe3636edb2fb73886
Parents: 3132adf
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Mon Feb 29 11:20:09 2016 +0000
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Mon Feb 29 11:20:09 2016 +0000

----------------------------------------------------------------------
 .../org/apache/cxf/transport/http/Headers.java  | 40 +++++++++++---------
 1 file changed, 23 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a669400f/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 03a3736..ad0d8c1 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
@@ -300,26 +300,32 @@ public class Headers {
         // 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 contentTypeSet = headers.containsKey(Message.CONTENT_TYPE);
+        if (!contentTypeSet) {
+            // if CT is not set then assume it has to be set by default
+            boolean dropContentType = false;
+            boolean getRequest = "GET".equals(message.get(Message.HTTP_REQUEST_METHOD));
+            boolean emptyRequest = getRequest || PropertyUtils.isTrue(message.get(EMPTY_REQUEST_PROPERTY));
+            // If it is an empty request (without a request body) then check further if CT still needs be set
+            if (emptyRequest) { 
+                Object setCtForEmptyRequestProp = message.getContextualProperty(SET_EMPTY_REQUEST_CT_PROPERTY);
+                if (setCtForEmptyRequestProp != null) {
+                    // If SET_EMPTY_REQUEST_CT_PROPERTY is set then do as a user prefers.
+                    // CT will be dropped if setting CT for empty requests was explicitly disabled
+                    dropContentType = PropertyUtils.isFalse(setCtForEmptyRequestProp);
+                } else if (getRequest) {
+                    // otherwise if it is GET then just drop it
+                    dropContentType = true;
+                }
                 
-        boolean dropContentType = false;
-        boolean emptyRequest = PropertyUtils.isTrue(message.get(EMPTY_REQUEST_PROPERTY));
-        if (emptyRequest) { 
-            Object setCtForEmptyRequestProp = message.getContextualProperty(SET_EMPTY_REQUEST_CT_PROPERTY);
-            if (setCtForEmptyRequestProp != null) {
-                // If SET_EMPTY_REQUEST_CT_PROPERTY is set then do as a user prefers.
-                // CT will be dropped if setting CT for empty requests was explicitly disabled
-                dropContentType = PropertyUtils.isFalse(setCtForEmptyRequestProp);
-            } else if ("GET".equals((String)message.get(Message.HTTP_REQUEST_METHOD))) {
-                // otherwise if it is GET then just drop it
-                dropContentType = true;
             }
-            
-        }
-        if (!dropContentType) {
-            String ct = emptyRequest && !headers.containsKey(Message.CONTENT_TYPE) ? "*/*" : determineContentType();
-            connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, ct);
+            if (!dropContentType) {
+                String ct = emptyRequest && !contentTypeSet ? "*/*" : determineContentType();
+                connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, ct);
+            }
+        } else {        
+            connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, determineContentType());
         }
-        
          
         transferProtocolHeadersToURLConnection(connection);
         logProtocolHeaders(Level.FINE);