cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject 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
Date Mon, 29 Feb 2016 11:26:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 8f6248067 -> 78f0f125c


[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/78f0f125
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/78f0f125
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/78f0f125

Branch: refs/heads/3.1.x-fixes
Commit: 78f0f125c5b9bc3ca0c490fb8f5f8e6106c44afd
Parents: 8f62480
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Feb 29 11:20:09 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Feb 29 11:26:32 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/78f0f125/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);


Mime
View raw message