From 9253bb791ed2fa880fed3808f06a4ccfc9d5d223 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 9 Jul 2012 15:57:49 +0200 Subject: [PATCH] Added capability of customizing request and response headers by overriding a method, and added Via header also on responses. --- .../eclipse/jetty/spdy/proxy/ProxyEngine.java | 27 ++++++++++++------- .../jetty/spdy/proxy/SPDYProxyEngine.java | 16 +++++------ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java index 1013430f17f..14d053a394d 100644 --- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java +++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.eclipse.jetty.spdy.api.Headers; +import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.StreamFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.util.log.Log; @@ -71,19 +72,27 @@ public abstract class ProxyEngine extends ServerSessionFrameListener.Adapter imp return name; } - protected void addRequestProxyHeaders(Headers headers) + protected void addRequestProxyHeaders(Stream stream, Headers headers) { - String newValue = ""; - Headers.Header header = headers.get("via"); - if (header != null) - newValue = header.valuesAsString() + ", "; - newValue += "http/1.1 " + getName(); - headers.put("via", newValue); + addViaHeader(headers); } - protected void addResponseProxyHeaders(Headers headers) + protected void addResponseProxyHeaders(Stream stream, Headers headers) + { + addViaHeader(headers); + } + + private void addViaHeader(Headers headers) + { + headers.add("Via", "http/1.1 " + getName()); + } + + protected void customizeRequestHeaders(Stream stream, Headers headers) + { + } + + protected void customizeResponseHeaders(Stream stream, Headers headers) { - // TODO: add Via header } public Map getProxyInfos() diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java index 536e966d856..55cce5d4d3b 100644 --- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java +++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java @@ -130,8 +130,6 @@ public class SPDYProxyEngine extends ProxyEngine return null; } - // TODO: give a chance to modify headers and rewrite URI - short serverVersion = proxyInfo.getVersion(); InetSocketAddress address = proxyInfo.getAddress(); Session serverSession = produceSession(host, serverVersion, address); @@ -145,10 +143,10 @@ public class SPDYProxyEngine extends ProxyEngine Set sessions = (Set)serverSession.getAttribute(CLIENT_SESSIONS_ATTRIBUTE); sessions.add(clientSession); + addRequestProxyHeaders(clientStream, headers); + customizeRequestHeaders(clientStream, headers); convert(clientVersion, serverVersion, headers); - addRequestProxyHeaders(headers); - SynInfo serverSynInfo = new SynInfo(headers, clientSynInfo.isClose()); StreamFrameListener listener = new ProxyStreamFrameListener(clientStream); StreamHandler handler = new StreamHandler(clientStream, serverSynInfo); @@ -256,11 +254,12 @@ public class SPDYProxyEngine extends ProxyEngine short serverVersion = stream.getSession().getVersion(); Headers headers = new Headers(replyInfo.getHeaders(), false); + + addResponseProxyHeaders(stream, headers); + customizeResponseHeaders(stream, headers); short clientVersion = this.clientStream.getSession().getVersion(); convert(serverVersion, clientVersion, headers); - addResponseProxyHeaders(headers); - this.replyInfo = new ReplyInfo(headers, replyInfo.isClose()); if (replyInfo.isClose()) reply(stream); @@ -484,14 +483,15 @@ public class SPDYProxyEngine extends ProxyEngine Headers headers = new Headers(serverSynInfo.getHeaders(), false); + addResponseProxyHeaders(serverStream, headers); + customizeResponseHeaders(serverStream, headers); Stream clientStream = (Stream)serverStream.getAssociatedStream().getAttribute(CLIENT_STREAM_ATTRIBUTE); convert(serverStream.getSession().getVersion(), clientStream.getSession().getVersion(), headers); - addResponseProxyHeaders(headers); - StreamHandler handler = new StreamHandler(clientStream, serverSynInfo); serverStream.setAttribute(STREAM_HANDLER_ATTRIBUTE, handler); clientStream.syn(new SynInfo(headers, serverSynInfo.isClose()), getTimeout(), TimeUnit.MILLISECONDS, handler); + return this; }