merge ProxyHTTPSPDYConnection change with 9.1

This commit is contained in:
Thomas Becker 2013-08-30 16:07:24 +02:00
parent 8e4bae0ccf
commit 8ba45188db
1 changed files with 50 additions and 4 deletions

View File

@ -27,6 +27,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;
@ -68,7 +69,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
public ProxyHTTPSPDYConnection(Connector connector, HttpConfiguration config, EndPoint endPoint, short version, ProxyEngineSelector proxyEngineSelector)
{
super(config,connector,endPoint);
super(config, connector, endPoint);
this.version = version;
this.proxyEngineSelector = proxyEngineSelector;
this.session = new HTTPSession(version, connector);
@ -95,7 +96,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
@Override
public boolean parsedHeader(HttpField field)
{
if (field.getHeader()==HttpHeader.HOST)
if (field.getHeader() == HttpHeader.HOST)
headers.put(HTTPSPDYHeader.HOST.name(version), field.getValue());
else
headers.put(field.getName(), field.getValue());
@ -144,10 +145,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
@ -238,6 +245,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();
@ -264,7 +273,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
long contentLength = fields.getLongField(HttpHeader.CONTENT_LENGTH.asString());
HttpGenerator.ResponseInfo info = new HttpGenerator.ResponseInfo(httpVersion, fields, contentLength, code,
reason, false);
// TODO use the async send
send(info, null, replyInfo.isClose());
@ -317,6 +326,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)