Repository: camel Updated Branches: refs/heads/master 7f0f97a8e -> 9a228c752
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/9a228c75 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9a228c75 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9a228c75 Branch: refs/heads/master Commit: 9a228c7527a6c3ab18c1e540cbdb906fab2e5021 Parents: ce9a322 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Wed May 27 16:31:10 2015 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Wed May 27 16:31:29 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/9a228c75/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/9a228c75/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); + } +}