416242 respect persistence headers in ProxyHTTPSPDYConnection

This commit is contained in:
Thomas Becker 2013-08-30 16:07:24 +02:00
parent 9565d2647e
commit fcdea1d4b4
1 changed files with 47 additions and 1 deletions

View File

@ -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)