SPDY: remove SPDY/3 support

This commit is contained in:
Jeff Pinner 2014-02-18 12:18:00 -08:00 committed by Trustin Lee
parent ff8df41541
commit 97f120330b
7 changed files with 33 additions and 80 deletions

View File

@ -25,9 +25,8 @@ import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.ssl.SslHandler;
import java.util.List;
import javax.net.ssl.SSLEngine;
import java.util.List;
/**
* {@link ChannelHandler} which is responsible to setup the {@link ChannelPipeline} either for HTTP or SPDY. This offers
@ -38,7 +37,6 @@ public abstract class SpdyOrHttpChooser extends ByteToMessageDecoder {
// TODO: Replace with generic NPN handler
public enum SelectedProtocol {
SPDY_3("spdy/3"),
SPDY_3_1("spdy/3.1"),
HTTP_1_1("http/1.1"),
HTTP_1_0("http/1.0"),
@ -111,9 +109,6 @@ public abstract class SpdyOrHttpChooser extends ByteToMessageDecoder {
case UNKNOWN:
// Not done with choosing the protocol, so just return here for now,
return false;
case SPDY_3:
addSpdyHandlers(ctx, SpdyVersion.SPDY_3);
break;
case SPDY_3_1:
addSpdyHandlers(ctx, SpdyVersion.SPDY_3_1);
break;
@ -160,7 +155,7 @@ public abstract class SpdyOrHttpChooser extends ByteToMessageDecoder {
/**
* Create the {@link ChannelHandler} that is responsible for handling the http responses when the
* {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_3} or {@link SelectedProtocol#SPDY_3_1}.
* when the {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_3_1}.
*
* By default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but sub-classes may
* override this to change the behaviour.

View File

@ -61,7 +61,6 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
private final boolean server;
private final int minorVersion;
private final boolean sessionFlowControl;
/**
* Creates a new session handler.
@ -78,7 +77,6 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
}
this.server = server;
minorVersion = version.getMinorVersion();
sessionFlowControl = version.useSessionFlowControl();
}
@Override
@ -110,25 +108,23 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
int streamId = spdyDataFrame.getStreamId();
if (sessionFlowControl) {
int deltaWindowSize = -1 * spdyDataFrame.content().readableBytes();
int newSessionWindowSize =
spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, deltaWindowSize);
int deltaWindowSize = -1 * spdyDataFrame.content().readableBytes();
int newSessionWindowSize =
spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, deltaWindowSize);
// Check if session window size is reduced beyond allowable lower bound
if (newSessionWindowSize < 0) {
issueSessionError(ctx, SpdySessionStatus.PROTOCOL_ERROR);
return;
}
// Check if session window size is reduced beyond allowable lower bound
if (newSessionWindowSize < 0) {
issueSessionError(ctx, SpdySessionStatus.PROTOCOL_ERROR);
return;
}
// Send a WINDOW_UPDATE frame if less than half the session window size remains
if (newSessionWindowSize <= initialReceiveWindowSize / 2) {
deltaWindowSize = initialReceiveWindowSize - newSessionWindowSize;
spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, deltaWindowSize);
SpdyWindowUpdateFrame spdyWindowUpdateFrame =
new DefaultSpdyWindowUpdateFrame(SPDY_SESSION_STREAM_ID, deltaWindowSize);
ctx.writeAndFlush(spdyWindowUpdateFrame);
}
// Send a WINDOW_UPDATE frame if less than half the session window size remains
if (newSessionWindowSize <= initialReceiveWindowSize / 2) {
int sessionDeltaWindowSize = initialReceiveWindowSize - newSessionWindowSize;
spdySession.updateReceiveWindowSize(SPDY_SESSION_STREAM_ID, sessionDeltaWindowSize);
SpdyWindowUpdateFrame spdyWindowUpdateFrame =
new DefaultSpdyWindowUpdateFrame(SPDY_SESSION_STREAM_ID, sessionDeltaWindowSize);
ctx.writeAndFlush(spdyWindowUpdateFrame);
}
// Check if we received a data frame for a Stream-ID which is not open
@ -165,7 +161,6 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
*/
// Update receive window size
int deltaWindowSize = -1 * spdyDataFrame.content().readableBytes();
int newWindowSize = spdySession.updateReceiveWindowSize(streamId, deltaWindowSize);
// Window size can become negative if we sent a SETTINGS frame that reduces the
@ -191,10 +186,10 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
// Send a WINDOW_UPDATE frame if less than half the stream window size remains
if (newWindowSize <= initialReceiveWindowSize / 2 && !spdyDataFrame.isLast()) {
deltaWindowSize = initialReceiveWindowSize - newWindowSize;
spdySession.updateReceiveWindowSize(streamId, deltaWindowSize);
int streamDeltaWindowSize = initialReceiveWindowSize - newWindowSize;
spdySession.updateReceiveWindowSize(streamId, streamDeltaWindowSize);
SpdyWindowUpdateFrame spdyWindowUpdateFrame =
new DefaultSpdyWindowUpdateFrame(streamId, deltaWindowSize);
new DefaultSpdyWindowUpdateFrame(streamId, streamDeltaWindowSize);
ctx.writeAndFlush(spdyWindowUpdateFrame);
}
@ -478,11 +473,8 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
synchronized (flowControlLock) {
int dataLength = spdyDataFrame.content().readableBytes();
int sendWindowSize = spdySession.getSendWindowSize(streamId);
if (sessionFlowControl) {
int sessionSendWindowSize = spdySession.getSendWindowSize(SPDY_SESSION_STREAM_ID);
sendWindowSize = Math.min(sendWindowSize, sessionSendWindowSize);
}
int sessionSendWindowSize = spdySession.getSendWindowSize(SPDY_SESSION_STREAM_ID);
sendWindowSize = Math.min(sendWindowSize, sessionSendWindowSize);
if (sendWindowSize <= 0) {
// Stream is stalled -- enqueue Data frame and return
@ -491,9 +483,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
} else if (sendWindowSize < dataLength) {
// Stream is not stalled but we cannot send the entire frame
spdySession.updateSendWindowSize(streamId, -1 * sendWindowSize);
if (sessionFlowControl) {
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * sendWindowSize);
}
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * sendWindowSize);
// Create a partial data frame whose length is the current window size
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamId,
@ -517,9 +507,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
} else {
// Window size is large enough to send entire data frame
spdySession.updateSendWindowSize(streamId, -1 * dataLength);
if (sessionFlowControl) {
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataLength);
}
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataLength);
// The transfer window size is pre-decremented when sending a data frame downstream.
// Close the session on write failures that leave the transfer window in a corrupt state.
@ -758,7 +746,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
private void updateSendWindowSize(final ChannelHandlerContext ctx, int streamId, int deltaWindowSize) {
synchronized (flowControlLock) {
int newWindowSize = spdySession.updateSendWindowSize(streamId, deltaWindowSize);
if (sessionFlowControl && streamId != SPDY_SESSION_STREAM_ID) {
if (streamId != SPDY_SESSION_STREAM_ID) {
int sessionSendWindowSize = spdySession.getSendWindowSize(SPDY_SESSION_STREAM_ID);
newWindowSize = Math.min(newWindowSize, sessionSendWindowSize);
}
@ -773,7 +761,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
SpdyDataFrame spdyDataFrame = pendingWrite.spdyDataFrame;
int dataFrameSize = spdyDataFrame.content().readableBytes();
int writeStreamId = spdyDataFrame.getStreamId();
if (sessionFlowControl && streamId == SPDY_SESSION_STREAM_ID) {
if (streamId == SPDY_SESSION_STREAM_ID) {
newWindowSize = Math.min(newWindowSize, spdySession.getSendWindowSize(writeStreamId));
}
@ -781,11 +769,9 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
// Window size is large enough to send entire data frame
spdySession.removePendingWrite(writeStreamId);
newWindowSize = spdySession.updateSendWindowSize(writeStreamId, -1 * dataFrameSize);
if (sessionFlowControl) {
int sessionSendWindowSize =
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataFrameSize);
newWindowSize = Math.min(newWindowSize, sessionSendWindowSize);
}
int sessionSendWindowSize =
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * dataFrameSize);
newWindowSize = Math.min(newWindowSize, sessionSendWindowSize);
// Close the local side of the stream if this is the last frame
if (spdyDataFrame.isLast()) {
@ -805,9 +791,7 @@ public class SpdySessionHandler extends ChannelHandlerAdapter {
} else {
// We can send a partial frame
spdySession.updateSendWindowSize(writeStreamId, -1 * newWindowSize);
if (sessionFlowControl) {
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * newWindowSize);
}
spdySession.updateSendWindowSize(SPDY_SESSION_STREAM_ID, -1 * newWindowSize);
// Create a partial data frame whose length is the current window size
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(writeStreamId,

View File

@ -16,17 +16,14 @@
package io.netty.handler.codec.spdy;
public enum SpdyVersion {
SPDY_3 (3, 0, false),
SPDY_3_1 (3, 1, true);
SPDY_3_1 (3, 1);
private final int version;
private final int minorVersion;
private final boolean sessionFlowControl;
private SpdyVersion(int version, int minorVersion, boolean sessionFlowControl) {
private SpdyVersion(int version, int minorVersion) {
this.version = version;
this.minorVersion = minorVersion;
this.sessionFlowControl = sessionFlowControl;
}
int getVersion() {
@ -36,8 +33,4 @@ public enum SpdyVersion {
int getMinorVersion() {
return minorVersion;
}
boolean useSessionFlowControl() {
return sessionFlowControl;
}
}

View File

@ -50,7 +50,6 @@ public class SpdyFrameDecoderTest {
@Test
public void testTooLargeHeaderNameOnSynStreamRequest() throws Exception {
testTooLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3);
testTooLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3_1);
}
@ -108,7 +107,6 @@ public class SpdyFrameDecoderTest {
@Test
public void testLargeHeaderNameOnSynStreamRequest() throws Exception {
testLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3);
testLargeHeaderNameOnSynStreamRequest(SpdyVersion.SPDY_3_1);
}

View File

@ -282,48 +282,36 @@ public class SpdySessionHandlerTest {
@Test
public void testSpdyClientSessionHandler() {
logger.info("Running: testSpdyClientSessionHandler v3");
testSpdySessionHandler(SpdyVersion.SPDY_3, false);
logger.info("Running: testSpdyClientSessionHandler v3.1");
testSpdySessionHandler(SpdyVersion.SPDY_3_1, false);
}
@Test
public void testSpdyClientSessionHandlerPing() {
logger.info("Running: testSpdyClientSessionHandlerPing v3");
testSpdySessionHandlerPing(SpdyVersion.SPDY_3, false);
logger.info("Running: testSpdyClientSessionHandlerPing v3.1");
testSpdySessionHandlerPing(SpdyVersion.SPDY_3_1, false);
}
@Test
public void testSpdyClientSessionHandlerGoAway() {
logger.info("Running: testSpdyClientSessionHandlerGoAway v3");
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3, false);
logger.info("Running: testSpdyClientSessionHandlerGoAway v3.1");
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3_1, false);
}
@Test
public void testSpdyServerSessionHandler() {
logger.info("Running: testSpdyServerSessionHandler v3");
testSpdySessionHandler(SpdyVersion.SPDY_3, true);
logger.info("Running: testSpdyServerSessionHandler v3.1");
testSpdySessionHandler(SpdyVersion.SPDY_3_1, true);
}
@Test
public void testSpdyServerSessionHandlerPing() {
logger.info("Running: testSpdyServerSessionHandlerPing v3");
testSpdySessionHandlerPing(SpdyVersion.SPDY_3, true);
logger.info("Running: testSpdyServerSessionHandlerPing v3.1");
testSpdySessionHandlerPing(SpdyVersion.SPDY_3_1, true);
}
@Test
public void testSpdyServerSessionHandlerGoAway() {
logger.info("Running: testSpdyServerSessionHandlerGoAway v3");
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3, true);
logger.info("Running: testSpdyServerSessionHandlerGoAway v3.1");
testSpdySessionHandlerGoAway(SpdyVersion.SPDY_3_1, true);
}

View File

@ -46,7 +46,7 @@ public class SpdyServerProvider implements ServerProvider {
@Override
public List<String> protocols() {
return Arrays.asList("spdy/3.1", "spdy/3", "http/1.1");
return Arrays.asList("spdy/3.1", "http/1.1");
}
@Override

View File

@ -149,10 +149,6 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
@Test(timeout = 15000)
public void testSpdyEcho() throws Throwable {
version = SpdyVersion.SPDY_3;
logger.info("Testing against SPDY v3");
run();
version = SpdyVersion.SPDY_3_1;
logger.info("Testing against SPDY v3.1");
run();
@ -162,7 +158,6 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
ByteBuf frames;
switch (version) {
case SPDY_3:
case SPDY_3_1:
frames = createFrames(3);
break;