Added capability of customizing request and response headers by overriding a method, and added Via header also on responses.
This commit is contained in:
parent
e3b6344641
commit
9253bb791e
|
@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import org.eclipse.jetty.spdy.api.Headers;
|
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.StreamFrameListener;
|
||||||
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
|
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
@ -71,19 +72,27 @@ public abstract class ProxyEngine extends ServerSessionFrameListener.Adapter imp
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addRequestProxyHeaders(Headers headers)
|
protected void addRequestProxyHeaders(Stream stream, Headers headers)
|
||||||
{
|
{
|
||||||
String newValue = "";
|
addViaHeader(headers);
|
||||||
Headers.Header header = headers.get("via");
|
|
||||||
if (header != null)
|
|
||||||
newValue = header.valuesAsString() + ", ";
|
|
||||||
newValue += "http/1.1 " + getName();
|
|
||||||
headers.put("via", newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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<String, ProxyInfo> getProxyInfos()
|
public Map<String, ProxyInfo> getProxyInfos()
|
||||||
|
|
|
@ -130,8 +130,6 @@ public class SPDYProxyEngine extends ProxyEngine
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: give a chance to modify headers and rewrite URI
|
|
||||||
|
|
||||||
short serverVersion = proxyInfo.getVersion();
|
short serverVersion = proxyInfo.getVersion();
|
||||||
InetSocketAddress address = proxyInfo.getAddress();
|
InetSocketAddress address = proxyInfo.getAddress();
|
||||||
Session serverSession = produceSession(host, serverVersion, address);
|
Session serverSession = produceSession(host, serverVersion, address);
|
||||||
|
@ -145,10 +143,10 @@ public class SPDYProxyEngine extends ProxyEngine
|
||||||
Set<Session> sessions = (Set<Session>)serverSession.getAttribute(CLIENT_SESSIONS_ATTRIBUTE);
|
Set<Session> sessions = (Set<Session>)serverSession.getAttribute(CLIENT_SESSIONS_ATTRIBUTE);
|
||||||
sessions.add(clientSession);
|
sessions.add(clientSession);
|
||||||
|
|
||||||
|
addRequestProxyHeaders(clientStream, headers);
|
||||||
|
customizeRequestHeaders(clientStream, headers);
|
||||||
convert(clientVersion, serverVersion, headers);
|
convert(clientVersion, serverVersion, headers);
|
||||||
|
|
||||||
addRequestProxyHeaders(headers);
|
|
||||||
|
|
||||||
SynInfo serverSynInfo = new SynInfo(headers, clientSynInfo.isClose());
|
SynInfo serverSynInfo = new SynInfo(headers, clientSynInfo.isClose());
|
||||||
StreamFrameListener listener = new ProxyStreamFrameListener(clientStream);
|
StreamFrameListener listener = new ProxyStreamFrameListener(clientStream);
|
||||||
StreamHandler handler = new StreamHandler(clientStream, serverSynInfo);
|
StreamHandler handler = new StreamHandler(clientStream, serverSynInfo);
|
||||||
|
@ -256,11 +254,12 @@ public class SPDYProxyEngine extends ProxyEngine
|
||||||
|
|
||||||
short serverVersion = stream.getSession().getVersion();
|
short serverVersion = stream.getSession().getVersion();
|
||||||
Headers headers = new Headers(replyInfo.getHeaders(), false);
|
Headers headers = new Headers(replyInfo.getHeaders(), false);
|
||||||
|
|
||||||
|
addResponseProxyHeaders(stream, headers);
|
||||||
|
customizeResponseHeaders(stream, headers);
|
||||||
short clientVersion = this.clientStream.getSession().getVersion();
|
short clientVersion = this.clientStream.getSession().getVersion();
|
||||||
convert(serverVersion, clientVersion, headers);
|
convert(serverVersion, clientVersion, headers);
|
||||||
|
|
||||||
addResponseProxyHeaders(headers);
|
|
||||||
|
|
||||||
this.replyInfo = new ReplyInfo(headers, replyInfo.isClose());
|
this.replyInfo = new ReplyInfo(headers, replyInfo.isClose());
|
||||||
if (replyInfo.isClose())
|
if (replyInfo.isClose())
|
||||||
reply(stream);
|
reply(stream);
|
||||||
|
@ -484,14 +483,15 @@ public class SPDYProxyEngine extends ProxyEngine
|
||||||
|
|
||||||
Headers headers = new Headers(serverSynInfo.getHeaders(), false);
|
Headers headers = new Headers(serverSynInfo.getHeaders(), false);
|
||||||
|
|
||||||
|
addResponseProxyHeaders(serverStream, headers);
|
||||||
|
customizeResponseHeaders(serverStream, headers);
|
||||||
Stream clientStream = (Stream)serverStream.getAssociatedStream().getAttribute(CLIENT_STREAM_ATTRIBUTE);
|
Stream clientStream = (Stream)serverStream.getAssociatedStream().getAttribute(CLIENT_STREAM_ATTRIBUTE);
|
||||||
convert(serverStream.getSession().getVersion(), clientStream.getSession().getVersion(), headers);
|
convert(serverStream.getSession().getVersion(), clientStream.getSession().getVersion(), headers);
|
||||||
|
|
||||||
addResponseProxyHeaders(headers);
|
|
||||||
|
|
||||||
StreamHandler handler = new StreamHandler(clientStream, serverSynInfo);
|
StreamHandler handler = new StreamHandler(clientStream, serverSynInfo);
|
||||||
serverStream.setAttribute(STREAM_HANDLER_ATTRIBUTE, handler);
|
serverStream.setAttribute(STREAM_HANDLER_ATTRIBUTE, handler);
|
||||||
clientStream.syn(new SynInfo(headers, serverSynInfo.isClose()), getTimeout(), TimeUnit.MILLISECONDS, handler);
|
clientStream.syn(new SynInfo(headers, serverSynInfo.isClose()), getTimeout(), TimeUnit.MILLISECONDS, handler);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue