Repository: camel
Updated Branches:
  refs/heads/master 44010a566 -> e5138c1d2


CAMEL-10665: Setting restlet standard headers should be done via their special 
api instead of making it easy :(


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

Branch: refs/heads/master
Commit: e5138c1d2bfe9d74f91d128c261cd95b9f8f4fd3
Parents: ffc745d
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Oct 5 13:31:12 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Oct 5 13:37:17 2017 +0200

----------------------------------------------------------------------
 .../restlet/DefaultRestletBinding.java          | 30 ++++++++++++++++----
 1 file changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e5138c1d/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
 
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index 4ec60bc..b190f5c 100644
--- 
a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ 
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -308,8 +308,8 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
         restletHeaders.removeAll(standardHeaders);
 
         // now add standard headers but via the special restlet api
-        LOG.debug("Detected {} extension headers", 
extensionHeaders.getHeaders().size());
-        LOG.debug("Detected {} standard headers", standardHeaders.size());
+        LOG.debug("Detected {} request extension headers", 
extensionHeaders.getHeaders().size());
+        LOG.debug("Detected {} request standard headers", 
standardHeaders.size());
 
         configureRestletRequestStandardHeaders(exchange, request, 
standardHeaders);
 
@@ -330,6 +330,13 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
             Header h = (Header) it.next();
             String key = h.getName();
             String value = h.getValue();
+
+            // ignore these headers
+            if ("Server".equalsIgnoreCase(key) || 
"Set-Cookie".equalsIgnoreCase(key) || "Expires".equalsIgnoreCase(key)
+                || "Connection".equalsIgnoreCase(key)) {
+                continue;
+            }
+
             if ("Authorization".equalsIgnoreCase(key)) {
                 // special workaround for restlet 
(https://github.com/restlet/restlet-framework-java/issues/1086)
                 ChallengeResponse c = new ChallengeResponse(new 
ChallengeScheme("", ""));
@@ -360,7 +367,7 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
                 }
             } else {
                 // TODO: implement all the other restlet standard headers
-                LOG.warn("Addition of the standard header \"{}\" is not 
allowed. Please use the equivalent property in the Restlet API.", key);
+                LOG.warn("Addition of the standard request header \"{}\" is 
not allowed. Please use the equivalent property in the Restlet API.", key);
             }
         }
     }
@@ -371,6 +378,12 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
             Header h = (Header) it.next();
             String key = h.getName();
             String value = h.getValue();
+
+            // ignore these headers
+            if ("Host".equalsIgnoreCase(key) || "Accept".equalsIgnoreCase(key) 
|| "Accept-encoding".equalsIgnoreCase(key)
+                || "User-Agent".equalsIgnoreCase(key) || 
"Referer".equalsIgnoreCase(key) || "Connection".equalsIgnoreCase(key)) {
+                continue;
+            }
             if ("Content-Type".equalsIgnoreCase(key)) {
                 MediaType mediaType = 
exchange.getContext().getTypeConverter().tryConvertTo(MediaType.class, 
exchange, value);
                 if (mediaType != null) {
@@ -388,9 +401,14 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
                 if (date != null) {
                     response.getEntity().setExpirationDate(date);
                 }
+            } else if ("Date".equalsIgnoreCase(key)) {
+                Date d = 
exchange.getContext().getTypeConverter().tryConvertTo(Date.class, exchange, 
value);
+                if (d != null) {
+                    response.setDate(d);
+                }
             } else {
                 // TODO: implement all the other restlet standard headers
-                LOG.warn("Addition of the standard header \"{}\" is not 
allowed. Please use the equivalent property in the Restlet API.", key);
+                LOG.warn("Addition of the standard response header \"{}\" is 
not allowed. Please use the equivalent property in the Restlet API.", key);
             }
         }
     }
@@ -507,8 +525,8 @@ public class DefaultRestletBinding implements 
RestletBinding, HeaderFilterStrate
         series.removeAll(standardHeaders);
 
         // now add standard headers but via the special restlet api
-        LOG.debug("Detected {} extension headers", 
extensionHeaders.getHeaders().size());
-        LOG.debug("Detected {} standard headers", standardHeaders.size());
+        LOG.debug("Detected {} response extension headers", 
extensionHeaders.getHeaders().size());
+        LOG.debug("Detected {} response standard headers", 
standardHeaders.size());
 
         configureRestletResponseStandardHeaders(exchange, response, 
standardHeaders);
 

Reply via email to