exchange.endExchange();
return;
}
request.setPath(requestURI.toString())
.setMethod(exchange.getRequestMethod());
final HeaderMap inboundRequestHeaders = exchange.getRequestHeaders();
final HeaderMap outboundRequestHeaders = request.getRequestHeaders();
copyHeaders(outboundRequestHeaders, inboundRequestHeaders);
if(!exchange.isPersistent()) {
//just because the client side is non-persistent
//we don't want to close the connection to the backend
outboundRequestHeaders.put(Headers.CONNECTION, "keep-alive");
}
for (Map.Entry<HttpString, ExchangeAttribute> entry : requestHeaders.entrySet()) {
String headerValue = entry.getValue().readAttribute(exchange);
if (headerValue == null || headerValue.isEmpty()) {
outboundRequestHeaders.remove(entry.getKey());
} else {
outboundRequestHeaders.put(entry.getKey(), headerValue.replace('\n', ' '));
}
}
SocketAddress address = exchange.getConnection().getPeerAddress();
if (address instanceof InetSocketAddress) {
outboundRequestHeaders.put(Headers.X_FORWARDED_FOR, ((InetSocketAddress) address).getHostString());
} else {
outboundRequestHeaders.put(Headers.X_FORWARDED_FOR, "localhost");
}
outboundRequestHeaders.put(Headers.X_FORWARDED_PROTO, exchange.getRequestScheme());
if (exchange.getRequestScheme().equals("https")) {
request.putAttachment(ProxiedRequestAttachments.IS_SSL, true);
}