Skip to content
Open

fix #110

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.synapse.transport.utils.conn.SynapseNHttpClientConnection;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Map;
import java.util.Iterator;

Expand Down Expand Up @@ -117,7 +118,8 @@ public static EndpointReference getDestinationEPR(MessageContext msgContext) {
*/
public static void removeUnwantedHeaders(MessageContext msgContext, TargetConfiguration targetConfiguration) {
Map headers = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
Map excessHeaders = (Map) msgContext.getProperty(NhttpConstants.EXCESS_TRANSPORT_HEADERS);

removeUnwantedExcessHeaders(msgContext);

if (headers == null || headers.isEmpty()) {
return;
Expand Down Expand Up @@ -159,6 +161,39 @@ public static void removeUnwantedHeaders(MessageContext msgContext, TargetConfig

}

/**
* Headers that frame the message body on the connection, or that control the connection
* itself. These are dictated by the transport and must never be carried over from an inbound
* message onto the outbound one.
*
* @param headerName the http header name to test
* @return true if the header frames the message or controls the connection
*/
public static boolean isConnectionFramingHeader(String headerName) {
return HTTP.TRANSFER_ENCODING.equalsIgnoreCase(headerName)
|| HTTP.CONTENT_LEN.equalsIgnoreCase(headerName)
|| HTTP.CONN_DIRECTIVE.equalsIgnoreCase(headerName);
}

/**
* Remove the connection framing headers from EXCESS_TRANSPORT_HEADERS.
*
* @param msgContext the Axis2 Message context holding the excess header map
*/
private static void removeUnwantedExcessHeaders(MessageContext msgContext) {
Map excessHeaders = (Map) msgContext.getProperty(NhttpConstants.EXCESS_TRANSPORT_HEADERS);

if (excessHeaders == null || excessHeaders.isEmpty()) {
return;
}

for (Object headerName : new ArrayList(excessHeaders.keySet())) {
if (headerName instanceof String && isConnectionFramingHeader((String) headerName)) {
excessHeaders.remove(headerName);
}
}
}

/**
* Determine the Http Status Code depending on the message type processed <br>
* (normal response versus fault response) as well as Axis2 message context properties set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public static SourceResponse create(MessageContext msgContext,
if (excessHeaders != null) {
for (Iterator iterator = excessHeaders.keySet().iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
if (PassThroughTransportUtils.isConnectionFramingHeader(key)) {
// A duplicate framing header must never be relayed onto the outbound message
continue;
}
for (String excessVal : (Collection<String>) excessHeaders.get(key)) {
sourceResponse.addHeader(key, (String) excessVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public static TargetRequest create(MessageContext msgContext,
if (excessHeaders != null) {
for (Iterator iterator = excessHeaders.keySet().iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
if (PassThroughTransportUtils.isConnectionFramingHeader(key)) {
// A duplicate framing header must never be relayed onto the outbound message
continue;
}
for (String excessVal : (Collection<String>) excessHeaders.get(key)) {
request.addHeader(key, (String) excessVal);
}
Expand Down
Loading