From fcdea1d4b43a3d96e48faa2b1a54c74ddaf36cbe Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Fri, 30 Aug 2013 16:07:24 +0200 Subject: [PATCH] 416242 respect persistence headers in ProxyHTTPSPDYConnection --- .../server/proxy/ProxyHTTPSPDYConnection.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java index 8b0d92a61a5..9a269fab319 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpGenerator; import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.HttpHeaderValue; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpParser; import org.eclipse.jetty.http.HttpVersion; @@ -143,10 +144,16 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse { stream.getStreamFrameListener().onData(stream, toDataInfo(content, true)); } + return false; + } + + @Override + public void completed() + { headers.clear(); stream = null; content = null; - return false; + super.completed(); } @Override @@ -235,6 +242,8 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse { Fields headers = new Fields(replyInfo.getHeaders(), false); + addPersistenceHeader(headers); + headers.remove(HTTPSPDYHeader.SCHEME.name(version)); String status = headers.remove(HTTPSPDYHeader.STATUS.name(version)).value(); @@ -314,6 +323,43 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse } } + private void addPersistenceHeader(Fields headersToAddTo) + { + HttpVersion httpVersion = HttpVersion.fromString(headers.get("version").value()); + boolean persistent = false; + switch (httpVersion) + { + case HTTP_1_0: + { + Fields.Field keepAliveHeader = headers.get(HttpHeader.KEEP_ALIVE.asString()); + if(keepAliveHeader!=null) + persistent = HttpHeaderValue.KEEP_ALIVE.asString().equals(keepAliveHeader.value()); + if (!persistent) + persistent = HttpMethod.CONNECT.is(headers.get("method").value()); + if (persistent) + headersToAddTo.add(HttpHeader.CONNECTION.asString(), HttpHeaderValue.KEEP_ALIVE.asString()); + break; + } + case HTTP_1_1: + { + Fields.Field connectionHeader = headers.get(HttpHeader.CONNECTION.asString()); + if(connectionHeader != null) + persistent = !HttpHeaderValue.CLOSE.asString().equals(connectionHeader.value()); + else + persistent = true; + if (!persistent) + persistent = HttpMethod.CONNECT.is(headers.get("method").value()); + if (!persistent) + headersToAddTo.add(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString()); + break; + } + default: + { + throw new IllegalStateException(); + } + } + } + private class HTTPPushStream extends StandardStream { private HTTPPushStream(int id, byte priority, ISession session, IStream associatedStream)