You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/05/27 16:13:35 UTC
[4/4] camel git commit: CAMEL-8774 merged the patch into camel-ahc
CAMEL-8774 merged the patch into camel-ahc
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2386efb2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2386efb2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2386efb2
Branch: refs/heads/camel-2.14.x
Commit: 2386efb25176aa2654217b5e5778c098f76e48fc
Parents: ba32ae9
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed May 27 16:31:10 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed May 27 22:12:12 2015 +0800
----------------------------------------------------------------------
.../camel/component/ahc/DefaultAhcBinding.java | 8 +-
.../ahc/HttpProtocolHeaderFilterStrategy.java | 88 ++++++++++++++++++++
2 files changed, 94 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2386efb2/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
index dbd8a96..8c57cd9 100644
--- a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
+++ b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/DefaultAhcBinding.java
@@ -45,14 +45,15 @@ import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.GZIPHelper;
import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.MessageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DefaultAhcBinding implements AhcBinding {
protected final Logger log = LoggerFactory.getLogger(this.getClass());
+ protected HeaderFilterStrategy httpProtocolHeaderFilterStrategy = new HttpProtocolHeaderFilterStrategy();
- @Override
public Request prepareRequest(AhcEndpoint endpoint, Exchange exchange) throws CamelExchangeException {
if (endpoint.isBridgeEndpoint()) {
exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
@@ -185,7 +186,10 @@ public class DefaultAhcBinding implements AhcBinding {
@Override
public void onStatusReceived(AhcEndpoint endpoint, Exchange exchange, HttpResponseStatus responseStatus) throws Exception {
- exchange.getOut().setHeaders(exchange.getIn().getHeaders());
+ // preserve headers from in by copying any non existing headers
+ // to avoid overriding existing headers with old values
+ // Just filter the http protocol headers
+ MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), httpProtocolHeaderFilterStrategy, false);
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, responseStatus.getStatusCode());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2386efb2/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpProtocolHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpProtocolHeaderFilterStrategy.java b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpProtocolHeaderFilterStrategy.java
new file mode 100644
index 0000000..02e3dde
--- /dev/null
+++ b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/HttpProtocolHeaderFilterStrategy.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.ahc;
+
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+
+
+public class HttpProtocolHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
+
+ public HttpProtocolHeaderFilterStrategy() {
+ initialize();
+ }
+
+ // Just add the http headers here
+ protected void initialize() {
+ getInFilter().add("host");
+
+ getInFilter().add("content-encoding");
+ getInFilter().add("content-language");
+ getInFilter().add("content-location");
+ getInFilter().add("content-md5");
+ getInFilter().add("content-length");
+ getInFilter().add("content-type");
+ getInFilter().add("content-range");
+
+ getInFilter().add("dav");
+ getInFilter().add("depth");
+ getInFilter().add("destination");
+ getInFilter().add("etag");
+ getInFilter().add("expect");
+ getInFilter().add("expires");
+ getInFilter().add("from");
+ getInFilter().add("if");
+ getInFilter().add("if-match");
+ getInFilter().add("if-modified-since");
+ getInFilter().add("if-none-match");
+ getInFilter().add("if-range");
+ getInFilter().add("if-unmodified-since");
+ getInFilter().add("last-modified");
+ getInFilter().add("location");
+ getInFilter().add("lock-token");
+ getInFilter().add("max-forwards");
+ getInFilter().add("overwrite");
+ getInFilter().add("pragma");
+ getInFilter().add("proxy-authenticate");
+ getInFilter().add("proxy-authorization");
+ getInFilter().add("range");
+ getInFilter().add("referer");
+ getInFilter().add("retry-after");
+ getInFilter().add("server");
+ getInFilter().add("status-uri");
+ getInFilter().add("te");
+ getInFilter().add("timeout");
+
+ getInFilter().add("user-agent");
+ getInFilter().add("vary");
+
+ getInFilter().add("www-authenticate");
+
+ // Add the filter for the Generic Message header
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
+ getInFilter().add("cache-control");
+ getInFilter().add("connection");
+ getInFilter().add("date");
+ getInFilter().add("pragma");
+ getInFilter().add("trailer");
+ getInFilter().add("transfer-encoding");
+ getInFilter().add("upgrade");
+ getInFilter().add("via");
+ getInFilter().add("warning");
+
+ setLowerCase(true);
+ }
+}