camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zregv...@apache.org
Subject camel git commit: CAMEL-10926 Set the Host header in Undertow pro...
Date Thu, 02 Mar 2017 12:41:34 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5ae014838 -> dd6f9ba60


CAMEL-10926 Set the Host header in Undertow pro...

...ducer

The implementation checks if the incoming Camel message has a `Host`
header, and if it's not set sets the `Host` HTTP header of the request
to authority of parsed URI value from given `httpURI` parameter
(transfered through `path` property of `ClientRequest`).


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

Branch: refs/heads/master
Commit: dd6f9ba60fb472b5a4e44f5b7d0a89b7dc895ade
Parents: 5ae0148
Author: Zoran Regvart <zregvart@apache.org>
Authored: Thu Mar 2 13:40:10 2017 +0100
Committer: Zoran Regvart <zregvart@apache.org>
Committed: Thu Mar 2 13:40:10 2017 +0100

----------------------------------------------------------------------
 .../component/undertow/DefaultUndertowHttpBinding.java | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dd6f9ba6/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
index 153279b..de64148 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.net.URI;
 import java.nio.ByteBuffer;
 import java.nio.channels.ReadableByteChannel;
 import java.util.Deque;
@@ -28,6 +29,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Optional;
 
 import javax.activation.FileDataSource;
 
@@ -39,6 +41,7 @@ import io.undertow.server.HttpServerExchange;
 import io.undertow.server.handlers.form.FormData;
 import io.undertow.server.handlers.form.FormData.FormValue;
 import io.undertow.server.handlers.form.FormDataParser;
+import io.undertow.util.HeaderMap;
 import io.undertow.util.Headers;
 import io.undertow.util.HttpString;
 import io.undertow.util.Methods;
@@ -350,14 +353,20 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding
{
 
         Object body = message.getBody();
 
+        final HeaderMap requestHeaders = clientRequest.getRequestHeaders();
+
         // set the content type in the response.
         String contentType = MessageHelper.getContentType(message);
         if (contentType != null) {
             // set content-type
-            clientRequest.getRequestHeaders().put(Headers.CONTENT_TYPE, contentType);
+            requestHeaders.put(Headers.CONTENT_TYPE, contentType);
             LOG.trace("Content-Type: {}", contentType);
         }
 
+        // Set the Host header
+        final String host = message.getHeader("Host", String.class);
+        requestHeaders.put(Headers.HOST, Optional.ofNullable(host).orElseGet(()-> URI.create(clientRequest.getPath()).getAuthority()));
+
         TypeConverter tc = message.getExchange().getContext().getTypeConverter();
 
         //copy headers from Message to Request
@@ -371,7 +380,7 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding
{
                 if (headerValue != null && headerFilterStrategy != null
                         && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue,
message.getExchange())) {
                     LOG.trace("HTTP-Header: {}={}", key, headerValue);
-                    clientRequest.getRequestHeaders().add(new HttpString(key), headerValue);
+                    requestHeaders.add(new HttpString(key), headerValue);
                 }
             }
         }


Mime
View raw message