SPDY: update object hierarchy

This commit is contained in:
Jeff Pinner 2013-06-04 14:32:11 -07:00 committed by Trustin Lee
parent 0b4adc0889
commit e279803587
35 changed files with 544 additions and 1230 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -22,11 +22,8 @@ import org.jboss.netty.util.internal.StringUtil;
/**
* The default {@link SpdyDataFrame} implementation.
*/
public class DefaultSpdyDataFrame implements SpdyDataFrame {
public class DefaultSpdyDataFrame extends DefaultSpdyStreamFrame implements SpdyDataFrame {
private int streamId;
private boolean last;
private boolean compressed;
private ChannelBuffer data = ChannelBuffers.EMPTY_BUFFER;
/**
@ -35,47 +32,7 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
* @param streamId the Stream-ID of this frame
*/
public DefaultSpdyDataFrame(int streamId) {
setStreamId(streamId);
}
@Deprecated
public int getStreamID() {
return getStreamId();
}
public int getStreamId() {
return streamId;
}
@Deprecated
public void setStreamID(int streamId) {
setStreamId(streamId);
}
public void setStreamId(int streamId) {
if (streamId <= 0) {
throw new IllegalArgumentException(
"Stream-ID must be positive: " + streamId);
}
this.streamId = streamId;
}
public boolean isLast() {
return last;
}
public void setLast(boolean last) {
this.last = last;
}
@Deprecated
public boolean isCompressed() {
return compressed;
}
@Deprecated
public void setCompressed(boolean compressed) {
this.compressed = compressed;
super(streamId);
}
public ChannelBuffer getData() {
@ -99,15 +56,13 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame {
buf.append(getClass().getSimpleName());
buf.append("(last: ");
buf.append(isLast());
buf.append("; compressed: ");
buf.append(isCompressed());
buf.append(')');
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(streamId);
buf.append(getStreamId());
buf.append(StringUtil.NEWLINE);
buf.append("--> Size = ");
buf.append(data.readableBytes());
buf.append(getData().readableBytes());
return buf.toString();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -55,20 +55,10 @@ public class DefaultSpdyGoAwayFrame implements SpdyGoAwayFrame {
setStatus(status);
}
@Deprecated
public int getLastGoodStreamID() {
return getLastGoodStreamId();
}
public int getLastGoodStreamId() {
return lastGoodStreamId;
}
@Deprecated
public void setLastGoodStreamID(int lastGoodStreamId) {
setLastGoodStreamId(lastGoodStreamId);
}
public void setLastGoodStreamId(int lastGoodStreamId) {
if (lastGoodStreamId < 0) {
throw new IllegalArgumentException("Last-good-stream-ID"
@ -91,10 +81,10 @@ public class DefaultSpdyGoAwayFrame implements SpdyGoAwayFrame {
buf.append(getClass().getSimpleName());
buf.append(StringUtil.NEWLINE);
buf.append("--> Last-good-stream-ID = ");
buf.append(lastGoodStreamId);
buf.append(getLastGoodStreamId());
buf.append(StringUtil.NEWLINE);
buf.append("--> Status: ");
buf.append(status.toString());
buf.append(getStatus().toString());
return buf.toString();
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.spdy;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.netty.util.internal.StringUtil;
/**
* The default {@link SpdyHeaderBlock} implementation.
*/
public class DefaultSpdyHeaderBlock implements SpdyHeaderBlock {
private boolean invalid;
private final SpdyHeaders headers = new SpdyHeaders();
/**
* Creates a new instance.
*/
protected DefaultSpdyHeaderBlock() {
}
public boolean isInvalid() {
return invalid;
}
public void setInvalid() {
invalid = true;
}
public void addHeader(final String name, final Object value) {
headers.addHeader(name, value);
}
public void setHeader(final String name, final Object value) {
headers.setHeader(name, value);
}
public void setHeader(final String name, final Iterable<?> values) {
headers.setHeader(name, values);
}
public void removeHeader(final String name) {
headers.removeHeader(name);
}
public void clearHeaders() {
headers.clearHeaders();
}
public String getHeader(final String name) {
return headers.getHeader(name);
}
public List<String> getHeaders(final String name) {
return headers.getHeaders(name);
}
public List<Map.Entry<String, String>> getHeaders() {
return headers.getHeaders();
}
public boolean containsHeader(final String name) {
return headers.containsHeader(name);
}
public Set<String> getHeaderNames() {
return headers.getHeaderNames();
}
protected void appendHeaders(StringBuilder buf) {
for (Map.Entry<String, String> e: getHeaders()) {
buf.append(" ");
buf.append(e.getKey());
buf.append(": ");
buf.append(e.getValue());
buf.append(StringUtil.NEWLINE);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -15,17 +15,20 @@
*/
package org.jboss.netty.handler.codec.spdy;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.netty.util.internal.StringUtil;
/**
* The default {@link SpdyHeadersFrame} implementation.
*/
public class DefaultSpdyHeadersFrame extends DefaultSpdyHeaderBlock
public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame
implements SpdyHeadersFrame {
private int streamId;
private boolean last;
private boolean invalid;
private final SpdyHeaders headers = new SpdyHeaders();
/**
* Creates a new instance.
@ -33,37 +36,55 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyHeaderBlock
* @param streamId the Stream-ID of this frame
*/
public DefaultSpdyHeadersFrame(int streamId) {
setStreamId(streamId);
super(streamId);
}
@Deprecated
public int getStreamID() {
return getStreamId();
public boolean isInvalid() {
return invalid;
}
public int getStreamId() {
return streamId;
public void setInvalid() {
invalid = true;
}
@Deprecated
public void setStreamID(int streamId) {
setStreamId(streamId);
public void addHeader(final String name, final Object value) {
headers.addHeader(name, value);
}
public void setStreamId(int streamId) {
if (streamId <= 0) {
throw new IllegalArgumentException(
"Stream-ID must be positive: " + streamId);
}
this.streamId = streamId;
public void setHeader(final String name, final Object value) {
headers.setHeader(name, value);
}
public boolean isLast() {
return last;
public void setHeader(final String name, final Iterable<?> values) {
headers.setHeader(name, values);
}
public void setLast(boolean last) {
this.last = last;
public void removeHeader(final String name) {
headers.removeHeader(name);
}
public void clearHeaders() {
headers.clearHeaders();
}
public String getHeader(final String name) {
return headers.getHeader(name);
}
public List<String> getHeaders(final String name) {
return headers.getHeaders(name);
}
public List<Map.Entry<String, String>> getHeaders() {
return headers.getHeaders();
}
public boolean containsHeader(final String name) {
return headers.containsHeader(name);
}
public Set<String> getHeaderNames() {
return headers.getHeaderNames();
}
@Override
@ -75,7 +96,7 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyHeaderBlock
buf.append(')');
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(streamId);
buf.append(getStreamId());
buf.append(StringUtil.NEWLINE);
buf.append("--> Headers:");
buf.append(StringUtil.NEWLINE);
@ -85,4 +106,14 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyHeaderBlock
buf.setLength(buf.length() - StringUtil.NEWLINE.length());
return buf.toString();
}
protected void appendHeaders(StringBuilder buf) {
for (Map.Entry<String, String> e: getHeaders()) {
buf.append(" ");
buf.append(e.getKey());
buf.append(": ");
buf.append(e.getValue());
buf.append(StringUtil.NEWLINE);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -33,20 +33,10 @@ public class DefaultSpdyPingFrame implements SpdyPingFrame {
setId(id);
}
@Deprecated
public int getID() {
return getId();
}
public int getId() {
return id;
}
@Deprecated
public void setID(int id) {
setId(id);
}
public void setId(int id) {
this.id = id;
}
@ -57,7 +47,7 @@ public class DefaultSpdyPingFrame implements SpdyPingFrame {
buf.append(getClass().getSimpleName());
buf.append(StringUtil.NEWLINE);
buf.append("--> ID = ");
buf.append(id);
buf.append(getId());
return buf.toString();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -20,9 +20,9 @@ import org.jboss.netty.util.internal.StringUtil;
/**
* The default {@link SpdyRstStreamFrame} implementation.
*/
public class DefaultSpdyRstStreamFrame implements SpdyRstStreamFrame {
public class DefaultSpdyRstStreamFrame extends DefaultSpdyStreamFrame
implements SpdyRstStreamFrame {
private int streamId;
private SpdyStreamStatus status;
/**
@ -42,32 +42,10 @@ public class DefaultSpdyRstStreamFrame implements SpdyRstStreamFrame {
* @param status the status of this frame
*/
public DefaultSpdyRstStreamFrame(int streamId, SpdyStreamStatus status) {
setStreamId(streamId);
super(streamId);
setStatus(status);
}
@Deprecated
public int getStreamID() {
return getStreamId();
}
public int getStreamId() {
return streamId;
}
@Deprecated
public void setStreamID(int streamId) {
setStreamId(streamId);
}
public void setStreamId(int streamId) {
if (streamId <= 0) {
throw new IllegalArgumentException(
"Stream-ID must be positive: " + streamId);
}
this.streamId = streamId;
}
public SpdyStreamStatus getStatus() {
return status;
}
@ -82,10 +60,10 @@ public class DefaultSpdyRstStreamFrame implements SpdyRstStreamFrame {
buf.append(getClass().getSimpleName());
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(streamId);
buf.append(getStreamId());
buf.append(StringUtil.NEWLINE);
buf.append("--> Status: ");
buf.append(status.toString());
buf.append(getStatus().toString());
return buf.toString();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -29,11 +29,6 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame {
private boolean clear;
private final Map<Integer, Setting> settingsMap = new TreeMap<Integer, Setting>();
@Deprecated
public Set<Integer> getIDs() {
return getIds();
}
public Set<Integer> getIds() {
return settingsMap.keySet();
}
@ -78,11 +73,6 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame {
}
}
@Deprecated
public boolean persistValue(int id) {
return isPersistValue(id);
}
public boolean isPersistValue(int id) {
Integer key = id;
if (settingsMap.containsKey(key)) {

View File

@ -0,0 +1,54 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.spdy;
/**
* The default {@link SpdyStreamFrame} implementation.
*/
public abstract class DefaultSpdyStreamFrame implements SpdyStreamFrame {
private int streamId;
private boolean last;
/**
* Creates a new instance.
*
* @param streamId the Stream-ID of this frame
*/
protected DefaultSpdyStreamFrame(int streamId) {
setStreamId(streamId);
}
public int getStreamId() {
return streamId;
}
public void setStreamId(int streamId) {
if (streamId <= 0) {
throw new IllegalArgumentException(
"Stream-ID must be positive: " + streamId);
}
this.streamId = streamId;
}
public boolean isLast() {
return last;
}
public void setLast(boolean last) {
this.last = last;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -20,49 +20,16 @@ import org.jboss.netty.util.internal.StringUtil;
/**
* The default {@link SpdySynReplyFrame} implementation.
*/
public class DefaultSpdySynReplyFrame extends DefaultSpdyHeaderBlock
public class DefaultSpdySynReplyFrame extends DefaultSpdyHeadersFrame
implements SpdySynReplyFrame {
private int streamId;
private boolean last;
/**
* Creates a new instance.
*
* @param streamId the Stream-ID of this frame
*/
public DefaultSpdySynReplyFrame(int streamId) {
setStreamId(streamId);
}
@Deprecated
public int getStreamID() {
return getStreamId();
}
public int getStreamId() {
return streamId;
}
@Deprecated
public void setStreamID(int streamId) {
setStreamId(streamId);
}
public void setStreamId(int streamId) {
if (streamId <= 0) {
throw new IllegalArgumentException(
"Stream-ID must be positive: " + streamId);
}
this.streamId = streamId;
}
public boolean isLast() {
return last;
}
public void setLast(boolean last) {
this.last = last;
super(streamId);
}
@Override
@ -74,7 +41,7 @@ public class DefaultSpdySynReplyFrame extends DefaultSpdyHeaderBlock
buf.append(')');
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(streamId);
buf.append(getStreamId());
buf.append(StringUtil.NEWLINE);
buf.append("--> Headers:");
buf.append(StringUtil.NEWLINE);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -20,65 +20,31 @@ import org.jboss.netty.util.internal.StringUtil;
/**
* The default {@link SpdySynStreamFrame} implementation.
*/
public class DefaultSpdySynStreamFrame extends DefaultSpdyHeaderBlock
public class DefaultSpdySynStreamFrame extends DefaultSpdyHeadersFrame
implements SpdySynStreamFrame {
private int streamId;
private int associatedToStreamId;
private byte priority;
private boolean last;
private boolean unidirectional;
/**
* Creates a new instance.
*
* @param streamID the Stream-ID of this frame
* @param streamId the Stream-ID of this frame
* @param associatedToStreamId the Associated-To-Stream-ID of this frame
* @param priority the priority of the stream
*/
public DefaultSpdySynStreamFrame(
int streamID, int associatedToStreamId, byte priority) {
setStreamId(streamID);
int streamId, int associatedToStreamId, byte priority) {
super(streamId);
setAssociatedToStreamId(associatedToStreamId);
setPriority(priority);
}
@Deprecated
public int getStreamID() {
return getStreamId();
}
public int getStreamId() {
return streamId;
}
@Deprecated
public void setStreamID(int streamId) {
setStreamId(streamId);
}
public void setStreamId(int streamId) {
if (streamId <= 0) {
throw new IllegalArgumentException(
"Stream-ID must be positive: " + streamId);
}
this.streamId = streamId;
}
@Deprecated
public int getAssociatedToStreamID() {
return getAssociatedToStreamId();
}
public int getAssociatedToStreamId() {
return associatedToStreamId;
}
@Deprecated
public void setAssociatedToStreamID(int associatedToStreamId) {
setAssociatedToStreamId(associatedToStreamId);
}
public void setAssociatedToStreamId(int associatedToStreamId) {
if (associatedToStreamId < 0) {
throw new IllegalArgumentException(
@ -100,14 +66,6 @@ public class DefaultSpdySynStreamFrame extends DefaultSpdyHeaderBlock
this.priority = priority;
}
public boolean isLast() {
return last;
}
public void setLast(boolean last) {
this.last = last;
}
public boolean isUnidirectional() {
return unidirectional;
}
@ -127,15 +85,15 @@ public class DefaultSpdySynStreamFrame extends DefaultSpdyHeaderBlock
buf.append(')');
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(streamId);
buf.append(getStreamId());
buf.append(StringUtil.NEWLINE);
if (associatedToStreamId != 0) {
buf.append("--> Associated-To-Stream-ID = ");
buf.append(associatedToStreamId);
buf.append(getAssociatedToStreamId());
buf.append(StringUtil.NEWLINE);
}
buf.append("--> Priority = ");
buf.append(priority);
buf.append(getPriority());
buf.append(StringUtil.NEWLINE);
buf.append("--> Headers:");
buf.append(StringUtil.NEWLINE);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -36,24 +36,14 @@ public class DefaultSpdyWindowUpdateFrame implements SpdyWindowUpdateFrame {
setDeltaWindowSize(deltaWindowSize);
}
@Deprecated
public int getStreamID() {
return getStreamId();
}
public int getStreamId() {
return streamId;
}
@Deprecated
public void setStreamID(int streamId) {
setStreamId(streamId);
}
public void setStreamId(int streamId) {
if (streamId <= 0) {
if (streamId < 0) {
throw new IllegalArgumentException(
"Stream-ID must be positive: " + streamId);
"Stream-ID cannot be negative: " + streamId);
}
this.streamId = streamId;
}
@ -77,10 +67,10 @@ public class DefaultSpdyWindowUpdateFrame implements SpdyWindowUpdateFrame {
buf.append(getClass().getSimpleName());
buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = ");
buf.append(streamId);
buf.append(getStreamId());
buf.append(StringUtil.NEWLINE);
buf.append("--> Delta-Window-Size = ");
buf.append(deltaWindowSize);
buf.append(getDeltaWindowSize());
return buf.toString();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -19,54 +19,9 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
/**
* A SPDY Protocol Data Frame
* A SPDY Protocol DATA Frame
*/
public interface SpdyDataFrame {
/**
* @deprecated Use {@link #getStreamId()} instead.
*/
@Deprecated
int getStreamID();
/**
* Returns the Stream-ID of this frame.
*/
int getStreamId();
/**
* @deprecated Use {@link #setStreamId(int)} instead.
*/
@Deprecated
void setStreamID(int streamID);
/**
* Sets the Stream-ID of this frame. The Stream-ID must be positive.
*/
void setStreamId(int streamID);
/**
* Returns {@code true} if this frame is the last frame to be transmitted
* on the stream.
*/
boolean isLast();
/**
* Sets if this frame is the last frame to be transmitted on the stream.
*/
void setLast(boolean last);
/**
* @deprecated Removed from SPDY specification.
*/
@Deprecated
boolean isCompressed();
/**
* @deprecated Removed from SPDY specification.
*/
@Deprecated
void setCompressed(boolean compressed);
public interface SpdyDataFrame extends SpdyStreamFrame {
/**
* Returns the data payload of this frame. If there is no data payload

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,8 +16,8 @@
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol NOOP Control Frame
* A SPDY Protocol Frame
*/
public interface SpdyNoOpFrame {
public interface SpdyFrame {
// Tag interface
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -31,17 +31,6 @@ public class SpdyFrameCodec implements ChannelUpstreamHandler,
private final SpdyFrameDecoder decoder;
private final SpdyFrameEncoder encoder;
/**
* Creates a new instance with the default decoder and encoder options
* ({@code version (2)}, {@code maxChunkSize (8192)},
* {@code maxHeaderSize (16384)}, {@code compressionLevel (6)},
* {@code windowBits (15)}, and {@code memLevel (8)}).
*/
@Deprecated
public SpdyFrameCodec() {
this(2);
}
/**
* Creates a new instance with the specified {@code version} and
* the default decoder and encoder options

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -26,7 +26,7 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
/**
* Decodes {@link ChannelBuffer}s into SPDY Data and Control Frames.
* Decodes {@link ChannelBuffer}s into SPDY Frames.
*/
public class SpdyFrameDecoder extends FrameDecoder {
@ -38,14 +38,14 @@ public class SpdyFrameDecoder extends FrameDecoder {
private State state;
private SpdySettingsFrame spdySettingsFrame;
private SpdyHeaderBlock spdyHeaderBlock;
private SpdyHeadersFrame spdyHeadersFrame;
// SPDY common header fields
private byte flags;
private int length;
private int version;
private int type;
private int streamID;
private int streamId;
// Header block decoding fields
private int headerSize;
@ -63,15 +63,6 @@ public class SpdyFrameDecoder extends FrameDecoder {
FRAME_ERROR
}
/**
* Creates a new instance with the default {@code version (2)},
* {@code maxChunkSize (8192)}, and {@code maxHeaderSize (16384)}.
*/
@Deprecated
public SpdyFrameDecoder() {
this(2);
}
/**
* Creates a new instance with the specified {@code version} and the default
* {@code maxChunkSize (8192)} and {@code maxHeaderSize (16384)}.
@ -134,13 +125,13 @@ public class SpdyFrameDecoder extends FrameDecoder {
// All length 0 frames must be generated now
if (length == 0) {
if (state == State.READ_DATA_FRAME) {
if (streamID == 0) {
if (streamId == 0) {
state = State.FRAME_ERROR;
fireProtocolException(ctx, "Received invalid data frame");
return null;
}
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(streamID);
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(streamId);
spdyDataFrame.setLast((flags & SPDY_DATA_FLAG_FIN) != 0);
state = State.READ_COMMON_HEADER;
return spdyDataFrame;
@ -233,12 +224,12 @@ public class SpdyFrameDecoder extends FrameDecoder {
case READ_HEADER_BLOCK_FRAME:
try {
spdyHeaderBlock = readHeaderBlockFrame(buffer);
if (spdyHeaderBlock != null) {
spdyHeadersFrame = readHeaderBlockFrame(buffer);
if (spdyHeadersFrame != null) {
if (length == 0) {
state = State.READ_COMMON_HEADER;
Object frame = spdyHeaderBlock;
spdyHeaderBlock = null;
Object frame = spdyHeadersFrame;
spdyHeadersFrame = null;
return frame;
}
state = State.READ_HEADER_BLOCK;
@ -258,15 +249,15 @@ public class SpdyFrameDecoder extends FrameDecoder {
decodeHeaderBlock(buffer.readSlice(compressedBytes));
} catch (Exception e) {
state = State.FRAME_ERROR;
spdyHeaderBlock = null;
spdyHeadersFrame = null;
decompressed = null;
Channels.fireExceptionCaught(ctx, e);
return null;
}
if (spdyHeaderBlock != null && spdyHeaderBlock.isInvalid()) {
Object frame = spdyHeaderBlock;
spdyHeaderBlock = null;
if (spdyHeadersFrame != null && spdyHeadersFrame.isInvalid()) {
Object frame = spdyHeadersFrame;
spdyHeadersFrame = null;
decompressed = null;
if (length == 0) {
state = State.READ_COMMON_HEADER;
@ -275,15 +266,15 @@ public class SpdyFrameDecoder extends FrameDecoder {
}
if (length == 0) {
Object frame = spdyHeaderBlock;
spdyHeaderBlock = null;
Object frame = spdyHeadersFrame;
spdyHeadersFrame = null;
state = State.READ_COMMON_HEADER;
return frame;
}
return null;
case READ_DATA_FRAME:
if (streamID == 0) {
if (streamId == 0) {
state = State.FRAME_ERROR;
fireProtocolException(ctx, "Received invalid data frame");
return null;
@ -297,7 +288,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
return null;
}
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(streamID);
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(streamId);
spdyDataFrame.setData(buffer.readBytes(dataLength));
length -= dataLength;
@ -378,14 +369,14 @@ public class SpdyFrameDecoder extends FrameDecoder {
return nextState;
} else {
// Decode data frame common header
streamID = getUnsignedInt(buffer, frameOffset);
streamId = getUnsignedInt(buffer, frameOffset);
return State.READ_DATA_FRAME;
}
}
private Object readControlFrame(ChannelBuffer buffer) {
int streamID;
int streamId;
int statusCode;
switch (type) {
case SPDY_RST_STREAM_FRAME:
@ -393,11 +384,11 @@ public class SpdyFrameDecoder extends FrameDecoder {
return null;
}
streamID = getUnsignedInt(buffer, buffer.readerIndex());
streamId = getUnsignedInt(buffer, buffer.readerIndex());
statusCode = getSignedInt(buffer, buffer.readerIndex() + 4);
buffer.skipBytes(8);
return new DefaultSpdyRstStreamFrame(streamID, statusCode);
return new DefaultSpdyRstStreamFrame(streamId, statusCode);
case SPDY_PING_FRAME:
if (buffer.readableBytes() < 4) {
@ -432,20 +423,20 @@ public class SpdyFrameDecoder extends FrameDecoder {
return null;
}
streamID = getUnsignedInt(buffer, buffer.readerIndex());
streamId = getUnsignedInt(buffer, buffer.readerIndex());
int deltaWindowSize = getUnsignedInt(buffer, buffer.readerIndex() + 4);
buffer.skipBytes(8);
return new DefaultSpdyWindowUpdateFrame(streamID, deltaWindowSize);
return new DefaultSpdyWindowUpdateFrame(streamId, deltaWindowSize);
default:
throw new Error("Shouldn't reach here.");
}
}
private SpdyHeaderBlock readHeaderBlockFrame(ChannelBuffer buffer) {
private SpdyHeadersFrame readHeaderBlockFrame(ChannelBuffer buffer) {
int minLength;
int streamID;
int streamId;
switch (type) {
case SPDY_SYN_STREAM_FRAME:
minLength = version < 3 ? 12 : 10;
@ -454,7 +445,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
}
int offset = buffer.readerIndex();
streamID = getUnsignedInt(buffer, offset);
streamId = getUnsignedInt(buffer, offset);
int associatedToStreamID = getUnsignedInt(buffer, offset + 4);
byte priority = (byte) (buffer.getByte(offset + 8) >> 5 & 0x07);
if (version < 3) {
@ -470,7 +461,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
}
SpdySynStreamFrame spdySynStreamFrame =
new DefaultSpdySynStreamFrame(streamID, associatedToStreamID, priority);
new DefaultSpdySynStreamFrame(streamId, associatedToStreamID, priority);
spdySynStreamFrame.setLast((flags & SPDY_FLAG_FIN) != 0);
spdySynStreamFrame.setUnidirectional((flags & SPDY_FLAG_UNIDIRECTIONAL) != 0);
@ -482,7 +473,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
return null;
}
streamID = getUnsignedInt(buffer, buffer.readerIndex());
streamId = getUnsignedInt(buffer, buffer.readerIndex());
buffer.skipBytes(4);
length -= 4;
@ -498,7 +489,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
length = 0;
}
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamID);
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamId);
spdySynReplyFrame.setLast((flags & SPDY_FLAG_FIN) != 0);
return spdySynReplyFrame;
@ -513,7 +504,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
return null;
}
streamID = getUnsignedInt(buffer, buffer.readerIndex());
streamId = getUnsignedInt(buffer, buffer.readerIndex());
buffer.skipBytes(4);
length -= 4;
@ -529,7 +520,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
length = 0;
}
SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(streamID);
SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(streamId);
spdyHeadersFrame.setLast((flags & SPDY_FLAG_FIN) != 0);
return spdyHeadersFrame;
@ -574,7 +565,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
headerBlockDecompressor.setInput(buffer);
headerBlockDecompressor.decode(decompressed);
if (spdyHeaderBlock == null) {
if (spdyHeadersFrame == null) {
// Only decompressing data to keep decompression context in sync
decompressed = null;
return;
@ -589,7 +580,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
}
numHeaders = readLengthField();
if (numHeaders < 0) {
spdyHeaderBlock.setInvalid();
spdyHeadersFrame.setInvalid();
return;
}
}
@ -608,7 +599,7 @@ public class SpdyFrameDecoder extends FrameDecoder {
// Recipients of a zero-length name must issue a stream error
if (nameLength <= 0) {
spdyHeaderBlock.setInvalid();
spdyHeadersFrame.setInvalid();
return;
}
headerSize += nameLength;
@ -628,8 +619,8 @@ public class SpdyFrameDecoder extends FrameDecoder {
String name = new String(nameBytes, "UTF-8");
// Check for identically named headers
if (spdyHeaderBlock.containsHeader(name)) {
spdyHeaderBlock.setInvalid();
if (spdyHeadersFrame.containsHeader(name)) {
spdyHeadersFrame.setInvalid();
return;
}
@ -643,17 +634,17 @@ public class SpdyFrameDecoder extends FrameDecoder {
// Recipients of illegal value fields must issue a stream error
if (valueLength < 0) {
spdyHeaderBlock.setInvalid();
spdyHeadersFrame.setInvalid();
return;
}
// SPDY/3 allows zero-length (empty) header values
if (valueLength == 0) {
if (version < 3) {
spdyHeaderBlock.setInvalid();
spdyHeadersFrame.setInvalid();
return;
} else {
spdyHeaderBlock.addHeader(name, "");
spdyHeadersFrame.addHeader(name, "");
numHeaders --;
this.headerSize = headerSize;
continue;
@ -685,16 +676,16 @@ public class SpdyFrameDecoder extends FrameDecoder {
if (index < valueBytes.length && valueBytes[index + 1] == (byte) 0) {
// Received multiple, in-sequence NULL characters
// Recipients of illegal value fields must issue a stream error
spdyHeaderBlock.setInvalid();
spdyHeadersFrame.setInvalid();
return;
}
String value = new String(valueBytes, offset, index - offset, "UTF-8");
try {
spdyHeaderBlock.addHeader(name, value);
spdyHeadersFrame.addHeader(name, value);
} catch (IllegalArgumentException e) {
// Name contains NULL or non-ascii characters
spdyHeaderBlock.setInvalid();
spdyHeadersFrame.setInvalid();
return;
}
index ++;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -30,7 +30,7 @@ import java.util.Set;
import static org.jboss.netty.handler.codec.spdy.SpdyCodecUtil.*;
/**
* Encodes a SPDY Data or Control Frame into a {@link ChannelBuffer}.
* Encodes a SPDY Frame into a {@link ChannelBuffer}.
*/
public class SpdyFrameEncoder implements ChannelDownstreamHandler {
@ -38,16 +38,6 @@ public class SpdyFrameEncoder implements ChannelDownstreamHandler {
private volatile boolean finished;
private final SpdyHeaderBlockCompressor headerBlockCompressor;
/**
* Creates a new instance with the default {@code version (2)},
* {@code compressionLevel (6)}, {@code windowBits (15)},
* and {@code memLevel (8)}.
*/
@Deprecated
public SpdyFrameEncoder() {
this(2, 6, 15, 8);
}
/**
* Creates a new instance with the specified {@code version} and the
* default {@code compressionLevel (6)}, {@code windowBits (15)},
@ -57,15 +47,6 @@ public class SpdyFrameEncoder implements ChannelDownstreamHandler {
this(version, 6, 15, 8);
}
/**
* Creates a new instance with the default {@code version (2)} and the
* specified parameters.
*/
@Deprecated
public SpdyFrameEncoder(int compressionLevel, int windowBits, int memLevel) {
this(2, compressionLevel, windowBits, memLevel);
}
/**
* Creates a new instance with the specified parameters.
*/
@ -255,17 +236,6 @@ public class SpdyFrameEncoder implements ChannelDownstreamHandler {
return;
}
if (msg instanceof SpdyNoOpFrame) {
ChannelBuffer frame = ChannelBuffers.buffer(
ByteOrder.BIG_ENDIAN, SPDY_HEADER_SIZE);
frame.writeShort(version | 0x8000);
frame.writeShort(SPDY_NOOP_FRAME);
frame.writeInt(0);
Channels.write(ctx, e.getFuture(), frame, e.getRemoteAddress());
return;
}
if (msg instanceof SpdyPingFrame) {
SpdyPingFrame spdyPingFrame = (SpdyPingFrame) msg;
@ -360,7 +330,7 @@ public class SpdyFrameEncoder implements ChannelDownstreamHandler {
}
}
private static ChannelBuffer encodeHeaderBlock(int version, SpdyHeaderBlock headerFrame)
private static ChannelBuffer encodeHeaderBlock(int version, SpdyHeadersFrame headerFrame)
throws Exception {
Set<String> names = headerFrame.getHeaderNames();
int numHeaders = names.size();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,27 +16,15 @@
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol GOAWAY Control Frame
* A SPDY Protocol GOAWAY Frame
*/
public interface SpdyGoAwayFrame {
/**
* @deprecated Use {@link #getLastGoodStreamId()} instead.
*/
@Deprecated
int getLastGoodStreamID();
public interface SpdyGoAwayFrame extends SpdyFrame {
/**
* Returns the Last-good-stream-ID of this frame.
*/
int getLastGoodStreamId();
/**
* @deprecated Use {@link #setLastGoodStreamId(int)} instead.
*/
@Deprecated
void setLastGoodStreamID(int lastGoodStreamId);
/**
* Sets the Last-good-stream-ID of this frame. The Last-good-stream-ID
* cannot be negative.

View File

@ -1,103 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.spdy;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* A SPDY Name/Value Header Block which provides common properties for
* {@link SpdySynStreamFrame}, {@link SpdySynReplyFrame}, and
* {@link SpdyHeadersFrame}.
* @see SpdyHeaders
*/
public interface SpdyHeaderBlock {
/**
* Returns {@code true} if this header block is invalid.
* A RST_STREAM frame with code PROTOCOL_ERROR should be sent.
*/
boolean isInvalid();
/**
* Marks this header block as invalid.
*/
void setInvalid();
/**
* Returns the header value with the specified header name. If there is
* more than one header value for the specified header name, the first
* value is returned.
*
* @return the header value or {@code null} if there is no such header
*/
String getHeader(String name);
/**
* Returns the header values with the specified header name.
*
* @return the {@link List} of header values. An empty list if there is no
* such header.
*/
List<String> getHeaders(String name);
/**
* Returns all header names and values that this block contains.
*
* @return the {@link List} of the header name-value pairs. An empty list
* if there is no header in this message.
*/
List<Map.Entry<String, String>> getHeaders();
/**
* Returns {@code true} if and only if there is a header with the specified
* header name.
*/
boolean containsHeader(String name);
/**
* Returns the {@link Set} of all header names that this block contains.
*/
Set<String> getHeaderNames();
/**
* Adds a new header with the specified name and value.
*/
void addHeader(String name, Object value);
/**
* Sets a new header with the specified name and value. If there is an
* existing header with the same name, the existing header is removed.
*/
void setHeader(String name, Object value);
/**
* Sets a new header with the specified name and values. If there is an
* existing header with the same name, the existing header is removed.
*/
void setHeader(String name, Iterable<?> values);
/**
* Removes the header with the specified name.
*/
void removeHeader(String name);
/**
* Removes all headers from this block.
*/
void clearHeaders();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -27,7 +27,7 @@ import java.util.TreeSet;
/**
* Provides the constants for the standard SPDY HTTP header names and commonly
* used utility methods that access a {@link SpdyHeaderBlock}.
* used utility methods that access a {@link SpdyHeadersFrame}.
* @apiviz.stereotype static
*/
public class SpdyHeaders {
@ -103,8 +103,8 @@ public class SpdyHeaders {
*
* @return the header value or {@code null} if there is no such header
*/
public static String getHeader(SpdyHeaderBlock block, String name) {
return block.getHeader(name);
public static String getHeader(SpdyHeadersFrame frame, String name) {
return frame.getHeader(name);
}
/**
@ -115,8 +115,8 @@ public class SpdyHeaders {
* @return the header value or the {@code defaultValue} if there is no such
* header
*/
public static String getHeader(SpdyHeaderBlock block, String name, String defaultValue) {
String value = block.getHeader(name);
public static String getHeader(SpdyHeadersFrame frame, String name, String defaultValue) {
String value = frame.getHeader(name);
if (value == null) {
return defaultValue;
}
@ -127,82 +127,66 @@ public class SpdyHeaders {
* Sets a new header with the specified name and value. If there is an
* existing header with the same name, the existing header is removed.
*/
public static void setHeader(SpdyHeaderBlock block, String name, Object value) {
block.setHeader(name, value);
public static void setHeader(SpdyHeadersFrame frame, String name, Object value) {
frame.setHeader(name, value);
}
/**
* Sets a new header with the specified name and values. If there is an
* existing header with the same name, the existing header is removed.
*/
public static void setHeader(SpdyHeaderBlock block, String name, Iterable<?> values) {
block.setHeader(name, values);
public static void setHeader(SpdyHeadersFrame frame, String name, Iterable<?> values) {
frame.setHeader(name, values);
}
/**
* Adds a new header with the specified name and value.
*/
public static void addHeader(SpdyHeaderBlock block, String name, Object value) {
block.addHeader(name, value);
public static void addHeader(SpdyHeadersFrame frame, String name, Object value) {
frame.addHeader(name, value);
}
/**
* Removes the SPDY host header.
*/
public static void removeHost(SpdyHeaderBlock block) {
block.removeHeader(HttpNames.HOST);
public static void removeHost(SpdyHeadersFrame frame) {
frame.removeHeader(HttpNames.HOST);
}
/**
* Returns the SPDY host header.
*/
public static String getHost(SpdyHeaderBlock block) {
return block.getHeader(HttpNames.HOST);
public static String getHost(SpdyHeadersFrame frame) {
return frame.getHeader(HttpNames.HOST);
}
/**
* Set the SPDY host header.
*/
public static void setHost(SpdyHeaderBlock block, String host) {
block.setHeader(HttpNames.HOST, host);
public static void setHost(SpdyHeadersFrame frame, String host) {
frame.setHeader(HttpNames.HOST, host);
}
/**
* Removes the HTTP method header.
*/
@Deprecated
public static void removeMethod(SpdyHeaderBlock block) {
removeMethod(2, block);
}
/**
* Removes the HTTP method header.
*/
public static void removeMethod(int spdyVersion, SpdyHeaderBlock block) {
public static void removeMethod(int spdyVersion, SpdyHeadersFrame frame) {
if (spdyVersion < 3) {
block.removeHeader(Spdy2HttpNames.METHOD);
frame.removeHeader(Spdy2HttpNames.METHOD);
} else {
block.removeHeader(HttpNames.METHOD);
frame.removeHeader(HttpNames.METHOD);
}
}
/**
* Returns the {@link HttpMethod} represented by the HTTP method header.
*/
@Deprecated
public static HttpMethod getMethod(SpdyHeaderBlock block) {
return getMethod(2, block);
}
/**
* Returns the {@link HttpMethod} represented by the HTTP method header.
*/
public static HttpMethod getMethod(int spdyVersion, SpdyHeaderBlock block) {
public static HttpMethod getMethod(int spdyVersion, SpdyHeadersFrame frame) {
try {
if (spdyVersion < 3) {
return HttpMethod.valueOf(block.getHeader(Spdy2HttpNames.METHOD));
return HttpMethod.valueOf(frame.getHeader(Spdy2HttpNames.METHOD));
} else {
return HttpMethod.valueOf(block.getHeader(HttpNames.METHOD));
return HttpMethod.valueOf(frame.getHeader(HttpNames.METHOD));
}
} catch (Exception e) {
return null;
@ -212,116 +196,68 @@ public class SpdyHeaders {
/**
* Sets the HTTP method header.
*/
@Deprecated
public static void setMethod(SpdyHeaderBlock block, HttpMethod method) {
setMethod(2, block, method);
}
/**
* Sets the HTTP method header.
*/
public static void setMethod(int spdyVersion, SpdyHeaderBlock block, HttpMethod method) {
public static void setMethod(int spdyVersion, SpdyHeadersFrame frame, HttpMethod method) {
if (spdyVersion < 3) {
block.setHeader(Spdy2HttpNames.METHOD, method.getName());
frame.setHeader(Spdy2HttpNames.METHOD, method.getName());
} else {
block.setHeader(HttpNames.METHOD, method.getName());
frame.setHeader(HttpNames.METHOD, method.getName());
}
}
/**
* Removes the URL scheme header.
*/
@Deprecated
public static void removeScheme(SpdyHeaderBlock block) {
removeMethod(2, block);
}
/**
* Removes the URL scheme header.
*/
public static void removeScheme(int spdyVersion, SpdyHeaderBlock block) {
public static void removeScheme(int spdyVersion, SpdyHeadersFrame frame) {
if (spdyVersion < 2) {
block.removeHeader(Spdy2HttpNames.SCHEME);
frame.removeHeader(Spdy2HttpNames.SCHEME);
} else {
block.removeHeader(HttpNames.SCHEME);
frame.removeHeader(HttpNames.SCHEME);
}
}
/**
* Returns the value of the URL scheme header.
*/
@Deprecated
public static String getScheme(SpdyHeaderBlock block) {
return getScheme(2, block);
}
/**
* Returns the value of the URL scheme header.
*/
public static String getScheme(int spdyVersion, SpdyHeaderBlock block) {
public static String getScheme(int spdyVersion, SpdyHeadersFrame frame) {
if (spdyVersion < 3) {
return block.getHeader(Spdy2HttpNames.SCHEME);
return frame.getHeader(Spdy2HttpNames.SCHEME);
} else {
return block.getHeader(HttpNames.SCHEME);
return frame.getHeader(HttpNames.SCHEME);
}
}
/**
* Sets the URL scheme header.
*/
@Deprecated
public static void setScheme(SpdyHeaderBlock block, String scheme) {
setScheme(2, block, scheme);
}
/**
* Sets the URL scheme header.
*/
public static void setScheme(int spdyVersion, SpdyHeaderBlock block, String scheme) {
public static void setScheme(int spdyVersion, SpdyHeadersFrame frame, String scheme) {
if (spdyVersion < 3) {
block.setHeader(Spdy2HttpNames.SCHEME, scheme);
frame.setHeader(Spdy2HttpNames.SCHEME, scheme);
} else {
block.setHeader(HttpNames.SCHEME, scheme);
frame.setHeader(HttpNames.SCHEME, scheme);
}
}
/**
* Removes the HTTP response status header.
*/
@Deprecated
public static void removeStatus(SpdyHeaderBlock block) {
removeMethod(2, block);
}
/**
* Removes the HTTP response status header.
*/
public static void removeStatus(int spdyVersion, SpdyHeaderBlock block) {
public static void removeStatus(int spdyVersion, SpdyHeadersFrame frame) {
if (spdyVersion < 3) {
block.removeHeader(Spdy2HttpNames.STATUS);
frame.removeHeader(Spdy2HttpNames.STATUS);
} else {
block.removeHeader(HttpNames.STATUS);
frame.removeHeader(HttpNames.STATUS);
}
}
/**
* Returns the {@link HttpResponseStatus} represented by the HTTP response status header.
*/
@Deprecated
public static HttpResponseStatus getStatus(SpdyHeaderBlock block) {
return getStatus(2, block);
}
/**
* Returns the {@link HttpResponseStatus} represented by the HTTP response status header.
*/
public static HttpResponseStatus getStatus(int spdyVersion, SpdyHeaderBlock block) {
public static HttpResponseStatus getStatus(int spdyVersion, SpdyHeadersFrame frame) {
try {
String status;
if (spdyVersion < 3) {
status = block.getHeader(Spdy2HttpNames.STATUS);
status = frame.getHeader(Spdy2HttpNames.STATUS);
} else {
status = block.getHeader(HttpNames.STATUS);
status = frame.getHeader(HttpNames.STATUS);
}
int space = status.indexOf(' ');
if (space == -1) {
@ -344,115 +280,67 @@ public class SpdyHeaders {
/**
* Sets the HTTP response status header.
*/
@Deprecated
public static void setStatus(SpdyHeaderBlock block, HttpResponseStatus status) {
setStatus(2, block, status);
}
/**
* Sets the HTTP response status header.
*/
public static void setStatus(int spdyVersion, SpdyHeaderBlock block, HttpResponseStatus status) {
public static void setStatus(int spdyVersion, SpdyHeadersFrame frame, HttpResponseStatus status) {
if (spdyVersion < 3) {
block.setHeader(Spdy2HttpNames.STATUS, status.toString());
frame.setHeader(Spdy2HttpNames.STATUS, status.toString());
} else {
block.setHeader(HttpNames.STATUS, status.toString());
frame.setHeader(HttpNames.STATUS, status.toString());
}
}
/**
* Removes the URL path header.
*/
@Deprecated
public static void removeUrl(SpdyHeaderBlock block) {
removeUrl(2, block);
}
/**
* Removes the URL path header.
*/
public static void removeUrl(int spdyVersion, SpdyHeaderBlock block) {
public static void removeUrl(int spdyVersion, SpdyHeadersFrame frame) {
if (spdyVersion < 3) {
block.removeHeader(Spdy2HttpNames.URL);
frame.removeHeader(Spdy2HttpNames.URL);
} else {
block.removeHeader(HttpNames.PATH);
frame.removeHeader(HttpNames.PATH);
}
}
/**
* Returns the value of the URL path header.
*/
@Deprecated
public static String getUrl(SpdyHeaderBlock block) {
return getUrl(2, block);
}
/**
* Returns the value of the URL path header.
*/
public static String getUrl(int spdyVersion, SpdyHeaderBlock block) {
public static String getUrl(int spdyVersion, SpdyHeadersFrame frame) {
if (spdyVersion < 3) {
return block.getHeader(Spdy2HttpNames.URL);
return frame.getHeader(Spdy2HttpNames.URL);
} else {
return block.getHeader(HttpNames.PATH);
return frame.getHeader(HttpNames.PATH);
}
}
/**
* Sets the URL path header.
*/
@Deprecated
public static void setUrl(SpdyHeaderBlock block, String path) {
setUrl(2, block, path);
}
/**
* Sets the URL path header.
*/
public static void setUrl(int spdyVersion, SpdyHeaderBlock block, String path) {
public static void setUrl(int spdyVersion, SpdyHeadersFrame frame, String path) {
if (spdyVersion < 3) {
block.setHeader(Spdy2HttpNames.URL, path);
frame.setHeader(Spdy2HttpNames.URL, path);
} else {
block.setHeader(HttpNames.PATH, path);
frame.setHeader(HttpNames.PATH, path);
}
}
/**
* Removes the HTTP version header.
*/
@Deprecated
public static void removeVersion(SpdyHeaderBlock block) {
removeVersion(2, block);
}
/**
* Removes the HTTP version header.
*/
public static void removeVersion(int spdyVersion, SpdyHeaderBlock block) {
public static void removeVersion(int spdyVersion, SpdyHeadersFrame frame) {
if (spdyVersion < 3) {
block.removeHeader(Spdy2HttpNames.VERSION);
frame.removeHeader(Spdy2HttpNames.VERSION);
} else {
block.removeHeader(HttpNames.VERSION);
frame.removeHeader(HttpNames.VERSION);
}
}
/**
* Returns the {@link HttpVersion} represented by the HTTP version header.
*/
@Deprecated
public static HttpVersion getVersion(SpdyHeaderBlock block) {
return getVersion(2, block);
}
/**
* Returns the {@link HttpVersion} represented by the HTTP version header.
*/
public static HttpVersion getVersion(int spdyVersion, SpdyHeaderBlock block) {
public static HttpVersion getVersion(int spdyVersion, SpdyHeadersFrame frame) {
try {
if (spdyVersion < 3) {
return HttpVersion.valueOf(block.getHeader(Spdy2HttpNames.VERSION));
return HttpVersion.valueOf(frame.getHeader(Spdy2HttpNames.VERSION));
} else {
return HttpVersion.valueOf(block.getHeader(HttpNames.VERSION));
return HttpVersion.valueOf(frame.getHeader(HttpNames.VERSION));
}
} catch (Exception e) {
return null;
@ -462,19 +350,11 @@ public class SpdyHeaders {
/**
* Sets the HTTP version header.
*/
@Deprecated
public static void setVersion(SpdyHeaderBlock block, HttpVersion httpVersion) {
setVersion(2, block, httpVersion);
}
/**
* Sets the HTTP version header.
*/
public static void setVersion(int spdyVersion, SpdyHeaderBlock block, HttpVersion httpVersion) {
public static void setVersion(int spdyVersion, SpdyHeadersFrame frame, HttpVersion httpVersion) {
if (spdyVersion < 3) {
block.setHeader(Spdy2HttpNames.VERSION, httpVersion.getText());
frame.setHeader(Spdy2HttpNames.VERSION, httpVersion.getText());
} else {
block.setHeader(HttpNames.VERSION, httpVersion.getText());
frame.setHeader(HttpNames.VERSION, httpVersion.getText());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -15,41 +15,86 @@
*/
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol HEADERS Control Frame
*/
public interface SpdyHeadersFrame extends SpdyHeaderBlock {
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @deprecated Use {@link #getStreamId()} instead.
* A SPDY Protocol HEADERS Frame
*/
@Deprecated
int getStreamID();
public interface SpdyHeadersFrame extends SpdyStreamFrame {
/**
* Returns the Stream-ID of this frame.
* Returns {@code true} if this header block is invalid.
* A RST_STREAM frame with code PROTOCOL_ERROR should be sent.
*/
int getStreamId();
boolean isInvalid();
/**
* @deprecated Use {@link #setStreamId(int)} instead.
* Marks this header block as invalid.
*/
@Deprecated
void setStreamID(int streamId);
void setInvalid();
/**
* Sets the Stream-ID of this frame. The Stream-ID must be positive.
* Returns the header value with the specified header name. If there is
* more than one header value for the specified header name, the first
* value is returned.
*
* @return the header value or {@code null} if there is no such header
*/
void setStreamId(int streamId);
String getHeader(String name);
/**
* Returns {@code true} if this frame is the last frame to be transmitted
* on the stream.
* Returns the header values with the specified header name.
*
* @return the {@link List} of header values. An empty list if there is no
* such header.
*/
boolean isLast();
List<String> getHeaders(String name);
/**
* Sets if this frame is the last frame to be transmitted on the stream.
* Returns all header names and values that this block contains.
*
* @return the {@link List} of the header name-value pairs. An empty list
* if there is no header in this message.
*/
void setLast(boolean last);
List<Map.Entry<String, String>> getHeaders();
/**
* Returns {@code true} if and only if there is a header with the specified
* header name.
*/
boolean containsHeader(String name);
/**
* Returns the {@link Set} of all header names that this block contains.
*/
Set<String> getHeaderNames();
/**
* Adds a new header with the specified name and value.
*/
void addHeader(String name, Object value);
/**
* Sets a new header with the specified name and value. If there is an
* existing header with the same name, the existing header is removed.
*/
void setHeader(String name, Object value);
/**
* Sets a new header with the specified name and values. If there is an
* existing header with the same name, the existing header is removed.
*/
void setHeader(String name, Iterable<?> values);
/**
* Removes the header with the specified name.
*/
void removeHeader(String name);
/**
* Removes all headers from this block.
*/
void clearHeaders();
}

View File

@ -30,14 +30,6 @@ public class SpdyHttpCodec implements ChannelUpstreamHandler, ChannelDownstreamH
private final SpdyHttpDecoder decoder;
private final SpdyHttpEncoder encoder;
/**
* Creates a new instance with the specified decoder options.
*/
@Deprecated
public SpdyHttpCodec(int maxContentLength) {
this(2, maxContentLength);
}
/**
* Creates a new instance with the specified decoder options.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -47,18 +47,6 @@ public class SpdyHttpDecoder extends OneToOneDecoder {
private final int maxContentLength;
private final Map<Integer, HttpMessage> messageMap;
/**
* Creates a new instance for the SPDY/2 protocol
*
* @param maxContentLength the maximum length of the message content.
* If the length of the message content exceeds this value,
* a {@link TooLongFrameException} will be raised.
*/
@Deprecated
public SpdyHttpDecoder(int maxContentLength) {
this(2, maxContentLength);
}
/**
* Creates a new instance.
*
@ -274,7 +262,7 @@ public class SpdyHttpDecoder extends OneToOneDecoder {
return null;
}
private static HttpRequest createHttpRequest(int spdyVersion, SpdyHeaderBlock requestFrame)
private static HttpRequest createHttpRequest(int spdyVersion, SpdyHeadersFrame requestFrame)
throws Exception {
// Create the first line of the request from the name/value pairs
HttpMethod method = SpdyHeaders.getMethod(spdyVersion, requestFrame);
@ -309,7 +297,7 @@ public class SpdyHttpDecoder extends OneToOneDecoder {
return httpRequest;
}
private static HttpResponse createHttpResponse(int spdyVersion, SpdyHeaderBlock responseFrame)
private static HttpResponse createHttpResponse(int spdyVersion, SpdyHeadersFrame responseFrame)
throws Exception {
// Create the first line of the response from the name/value pairs
HttpResponseStatus status = SpdyHeaders.getStatus(spdyVersion, responseFrame);

View File

@ -128,14 +128,6 @@ public class SpdyHttpEncoder implements ChannelDownstreamHandler {
private final int spdyVersion;
private volatile int currentStreamID;
/**
* Creates a new instance for the SPDY/2 protocol
*/
@Deprecated
public SpdyHttpEncoder() {
this(2);
}
/**
* Creates a new instance.
*
@ -333,7 +325,7 @@ public class SpdyHttpEncoder implements ChannelDownstreamHandler {
int streamID = SpdyHttpHeaders.getStreamId(httpResponse);
SpdyHttpHeaders.removeStreamId(httpResponse);
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-ENcoding
// The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
// headers are not valid and MUST not be sent.
httpResponse.removeHeader(HttpHeaders.Names.CONNECTION);
httpResponse.removeHeader("Keep-Alive");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -58,14 +58,6 @@ public final class SpdyHttpHeaders {
private SpdyHttpHeaders() {
}
/**
* @deprecated Use {@link #removeStreamId(HttpMessage)} instead.
*/
@Deprecated
public static void removeStreamID(HttpMessage message) {
removeStreamId(message);
}
/**
* Removes the {@code "X-SPDY-Stream-ID"} header.
*/
@ -73,14 +65,6 @@ public final class SpdyHttpHeaders {
message.removeHeader(Names.STREAM_ID);
}
/**
* @deprecated Use {@link #getStreamId(HttpMessage)} instead.
*/
@Deprecated
public static int getStreamID(HttpMessage message) {
return getStreamId(message);
}
/**
* Returns the value of the {@code "X-SPDY-Stream-ID"} header.
*/
@ -88,14 +72,6 @@ public final class SpdyHttpHeaders {
return HttpHeaders.getIntHeader(message, Names.STREAM_ID);
}
/**
* @deprecated Use {@link #setStreamId(HttpMessage, int)} instead.
*/
@Deprecated
public static void setStreamID(HttpMessage message, int streamId) {
setStreamId(message, streamId);
}
/**
* Sets the {@code "X-SPDY-Stream-ID"} header.
*/
@ -103,14 +79,6 @@ public final class SpdyHttpHeaders {
HttpHeaders.setIntHeader(message, Names.STREAM_ID, streamId);
}
/**
* @deprecated Use {@link #removeAssociatedToStreamId(HttpMessage)} instead.
*/
@Deprecated
public static void removeAssociatedToStreamID(HttpMessage message) {
removeAssociatedToStreamId(message);
}
/**
* Removes the {@code "X-SPDY-Associated-To-Stream-ID"} header.
*/
@ -118,14 +86,6 @@ public final class SpdyHttpHeaders {
message.removeHeader(Names.ASSOCIATED_TO_STREAM_ID);
}
/**
* @deprecated Use {@link #getAssociatedToStreamId(HttpMessage)} instead.
*/
@Deprecated
public static int getAssociatedToStreamID(HttpMessage message) {
return getAssociatedToStreamId(message);
}
/**
* Returns the value of the {@code "X-SPDY-Associated-To-Stream-ID"} header.
*
@ -136,14 +96,6 @@ public final class SpdyHttpHeaders {
return HttpHeaders.getIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, 0);
}
/**
* @deprecated Use {@link #setAssociatedToStreamId(HttpMessage, int)} instead.
*/
@Deprecated
public static void setAssociatedToStreamID(HttpMessage message, int associatedToStreamId) {
setAssociatedToStreamId(message, associatedToStreamId);
}
/**
* Sets the {@code "X-SPDY-Associated-To-Stream-ID"} header.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,27 +16,15 @@
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol PING Control Frame
* A SPDY Protocol PING Frame
*/
public interface SpdyPingFrame {
/**
* @deprecated Use {@link #getId()} instead.
*/
@Deprecated
int getID();
public interface SpdyPingFrame extends SpdyFrame {
/**
* Returns the ID of this frame.
*/
int getId();
/**
* @deprecated Use {@link #setId(int)} instead.
*/
@Deprecated
void setID(int id);
/**
* Sets the ID of this frame.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,31 +16,9 @@
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol RST_STREAM Control Frame
* A SPDY Protocol RST_STREAM Frame
*/
public interface SpdyRstStreamFrame {
/**
* @deprecated Use {@link #getStreamId()} instead.
*/
@Deprecated
int getStreamID();
/**
* Returns the Stream-ID of this frame.
*/
int getStreamId();
/**
* @deprecated Use {@link #setStreamId(int)} instead.
*/
@Deprecated
void setStreamID(int streamId);
/**
* Sets the Stream-ID of this frame. The Stream-ID must be positive.
*/
void setStreamId(int streamId);
public interface SpdyRstStreamFrame extends SpdyStreamFrame {
/**
* Returns the status of this frame.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -42,7 +42,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
private static final SpdyProtocolException PROTOCOL_EXCEPTION = new SpdyProtocolException();
private final SpdySession spdySession = new SpdySession();
private volatile int lastGoodStreamID;
private volatile int lastGoodStreamId;
private volatile int remoteConcurrentStreams;
private volatile int localConcurrentStreams;
@ -64,19 +64,6 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
private final boolean server;
private final boolean flowControl;
/**
* Creates a new SPDY/2 session handler.
*
* @param server {@code true} if and only if this session handler should
* handle the server endpoint of the connection.
* {@code false} if and only if this session handler should
* handle the client endpoint of the connection.
*/
@Deprecated
public SpdySessionHandler(boolean server) {
this(2, server);
}
/**
* Creates a new session handler.
*
@ -126,27 +113,27 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
*/
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
int streamID = spdyDataFrame.getStreamId();
int streamId = spdyDataFrame.getStreamId();
// Check if we received a data frame for a Stream-ID which is not open
if (!spdySession.isActiveStream(streamID)) {
if (streamID <= lastGoodStreamID) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.PROTOCOL_ERROR);
if (!spdySession.isActiveStream(streamId)) {
if (streamId <= lastGoodStreamId) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.PROTOCOL_ERROR);
} else if (!sentGoAwayFrame) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.INVALID_STREAM);
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.INVALID_STREAM);
}
return;
}
// Check if we received a data frame for a stream which is half-closed
if (spdySession.isRemoteSideClosed(streamID)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.STREAM_ALREADY_CLOSED);
if (spdySession.isRemoteSideClosed(streamId)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.STREAM_ALREADY_CLOSED);
return;
}
// Check if we received a data frame before receiving a SYN_REPLY
if (!isRemoteInitiatedID(streamID) && !spdySession.hasReceivedReply(streamID)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.PROTOCOL_ERROR);
if (!isRemoteInitiatedID(streamId) && !spdySession.hasReceivedReply(streamId)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.PROTOCOL_ERROR);
return;
}
@ -159,15 +146,15 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
if (flowControl) {
// Update receive window size
int deltaWindowSize = -1 * spdyDataFrame.getData().readableBytes();
int newWindowSize = spdySession.updateReceiveWindowSize(streamID, deltaWindowSize);
int newWindowSize = spdySession.updateReceiveWindowSize(streamId, deltaWindowSize);
// Window size can become negative if we sent a SETTINGS frame that reduces the
// size of the transfer window after the peer has written data frames.
// The value is bounded by the length that SETTINGS frame decrease the window.
// This difference is stored for the session when writing the SETTINGS frame
// and is cleared once we send a WINDOW_UPDATE frame.
if (newWindowSize < spdySession.getReceiveWindowSizeLowerBound(streamID)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.FLOW_CONTROL_ERROR);
if (newWindowSize < spdySession.getReceiveWindowSizeLowerBound(streamId)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.FLOW_CONTROL_ERROR);
return;
}
@ -175,7 +162,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
// Send data frames upstream in initialReceiveWindowSize chunks
if (newWindowSize < 0) {
while (spdyDataFrame.getData().readableBytes() > initialReceiveWindowSize) {
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamID);
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamId);
partialDataFrame.setData(spdyDataFrame.getData().readSlice(initialReceiveWindowSize));
Channels.fireMessageReceived(ctx, partialDataFrame, e.getRemoteAddress());
}
@ -184,9 +171,9 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
// Send a WINDOW_UPDATE frame if less than half the window size remains
if (newWindowSize <= initialReceiveWindowSize / 2 && !spdyDataFrame.isLast()) {
deltaWindowSize = initialReceiveWindowSize - newWindowSize;
spdySession.updateReceiveWindowSize(streamID, deltaWindowSize);
spdySession.updateReceiveWindowSize(streamId, deltaWindowSize);
SpdyWindowUpdateFrame spdyWindowUpdateFrame =
new DefaultSpdyWindowUpdateFrame(streamID, deltaWindowSize);
new DefaultSpdyWindowUpdateFrame(streamId, deltaWindowSize);
Channels.write(
ctx, Channels.future(e.getChannel()), spdyWindowUpdateFrame, e.getRemoteAddress());
}
@ -194,7 +181,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
// Close the remote side of the stream if this is the last frame
if (spdyDataFrame.isLast()) {
halfCloseStream(streamID, true);
halfCloseStream(streamId, true);
}
} else if (msg instanceof SpdySynStreamFrame) {
@ -214,18 +201,18 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
*/
SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg;
int streamID = spdySynStreamFrame.getStreamId();
int streamId = spdySynStreamFrame.getStreamId();
// Check if we received a valid SYN_STREAM frame
if (spdySynStreamFrame.isInvalid() ||
!isRemoteInitiatedID(streamID) ||
spdySession.isActiveStream(streamID)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.PROTOCOL_ERROR);
!isRemoteInitiatedID(streamId) ||
spdySession.isActiveStream(streamId)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.PROTOCOL_ERROR);
return;
}
// Stream-IDs must be monotonically increasing
if (streamID <= lastGoodStreamID) {
if (streamId <= lastGoodStreamId) {
issueSessionError(ctx, e.getChannel(), e.getRemoteAddress(), SpdySessionStatus.PROTOCOL_ERROR);
return;
}
@ -234,8 +221,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
byte priority = spdySynStreamFrame.getPriority();
boolean remoteSideClosed = spdySynStreamFrame.isLast();
boolean localSideClosed = spdySynStreamFrame.isUnidirectional();
if (!acceptStream(streamID, priority, remoteSideClosed, localSideClosed)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.REFUSED_STREAM);
if (!acceptStream(streamId, priority, remoteSideClosed, localSideClosed)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.REFUSED_STREAM);
return;
}
@ -249,27 +236,27 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
*/
SpdySynReplyFrame spdySynReplyFrame = (SpdySynReplyFrame) msg;
int streamID = spdySynReplyFrame.getStreamId();
int streamId = spdySynReplyFrame.getStreamId();
// Check if we received a valid SYN_REPLY frame
if (spdySynReplyFrame.isInvalid() ||
isRemoteInitiatedID(streamID) ||
spdySession.isRemoteSideClosed(streamID)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.INVALID_STREAM);
isRemoteInitiatedID(streamId) ||
spdySession.isRemoteSideClosed(streamId)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.INVALID_STREAM);
return;
}
// Check if we have received multiple frames for the same Stream-ID
if (spdySession.hasReceivedReply(streamID)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.STREAM_IN_USE);
if (spdySession.hasReceivedReply(streamId)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.STREAM_IN_USE);
return;
}
spdySession.receivedReply(streamID);
spdySession.receivedReply(streamId);
// Close the remote side of the stream if this is the last frame
if (spdySynReplyFrame.isLast()) {
halfCloseStream(streamID, true);
halfCloseStream(streamId, true);
}
} else if (msg instanceof SpdyRstStreamFrame) {
@ -343,22 +330,22 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
} else if (msg instanceof SpdyHeadersFrame) {
SpdyHeadersFrame spdyHeadersFrame = (SpdyHeadersFrame) msg;
int streamID = spdyHeadersFrame.getStreamId();
int streamId = spdyHeadersFrame.getStreamId();
// Check if we received a valid HEADERS frame
if (spdyHeadersFrame.isInvalid()) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.PROTOCOL_ERROR);
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.PROTOCOL_ERROR);
return;
}
if (spdySession.isRemoteSideClosed(streamID)) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.INVALID_STREAM);
if (spdySession.isRemoteSideClosed(streamId)) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.INVALID_STREAM);
return;
}
// Close the remote side of the stream if this is the last frame
if (spdyHeadersFrame.isLast()) {
halfCloseStream(streamID, true);
halfCloseStream(streamId, true);
}
} else if (msg instanceof SpdyWindowUpdateFrame) {
@ -375,21 +362,21 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
if (flowControl) {
SpdyWindowUpdateFrame spdyWindowUpdateFrame = (SpdyWindowUpdateFrame) msg;
int streamID = spdyWindowUpdateFrame.getStreamId();
int streamId = spdyWindowUpdateFrame.getStreamId();
int deltaWindowSize = spdyWindowUpdateFrame.getDeltaWindowSize();
// Ignore frames for half-closed streams
if (spdySession.isLocalSideClosed(streamID)) {
if (spdySession.isLocalSideClosed(streamId)) {
return;
}
// Check for numerical overflow
if (spdySession.getSendWindowSize(streamID) > Integer.MAX_VALUE - deltaWindowSize) {
issueStreamError(ctx, e.getRemoteAddress(), streamID, SpdyStreamStatus.FLOW_CONTROL_ERROR);
if (spdySession.getSendWindowSize(streamId) > Integer.MAX_VALUE - deltaWindowSize) {
issueStreamError(ctx, e.getRemoteAddress(), streamId, SpdyStreamStatus.FLOW_CONTROL_ERROR);
return;
}
updateSendWindowSize(ctx, streamID, deltaWindowSize);
updateSendWindowSize(ctx, streamId, deltaWindowSize);
}
return;
}
@ -441,10 +428,10 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
if (msg instanceof SpdyDataFrame) {
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
final int streamID = spdyDataFrame.getStreamId();
final int streamId = spdyDataFrame.getStreamId();
// Frames must not be sent on half-closed streams
if (spdySession.isLocalSideClosed(streamID)) {
if (spdySession.isLocalSideClosed(streamId)) {
e.getFuture().setFailure(PROTOCOL_EXCEPTION);
return;
}
@ -465,22 +452,22 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
if (flowControl) {
synchronized (flowControlLock) {
int dataLength = spdyDataFrame.getData().readableBytes();
int sendWindowSize = spdySession.getSendWindowSize(streamID);
int sendWindowSize = spdySession.getSendWindowSize(streamId);
if (sendWindowSize <= 0) {
// Stream is stalled -- enqueue Data frame and return
spdySession.putPendingWrite(streamID, e);
spdySession.putPendingWrite(streamId, e);
return;
} else if (sendWindowSize < dataLength) {
// Stream is not stalled but we cannot send the entire frame
spdySession.updateSendWindowSize(streamID, -1 * sendWindowSize);
spdySession.updateSendWindowSize(streamId, -1 * sendWindowSize);
// Create a partial data frame whose length is the current window size
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamID);
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamId);
partialDataFrame.setData(spdyDataFrame.getData().readSlice(sendWindowSize));
// Enqueue the remaining data (will be the first frame queued)
spdySession.putPendingWrite(streamID, e);
spdySession.putPendingWrite(streamId, e);
ChannelFuture writeFuture = Channels.future(e.getChannel());
@ -492,7 +479,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
issueStreamError(
context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
context, remoteAddress, streamId, SpdyStreamStatus.INTERNAL_ERROR);
}
}
});
@ -501,7 +488,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
return;
} else {
// Window size is large enough to send entire data frame
spdySession.updateSendWindowSize(streamID, -1 * dataLength);
spdySession.updateSendWindowSize(streamId, -1 * dataLength);
// The transfer window size is pre-decremented when sending a data frame downstream.
// Close the stream on write failures that leaves the transfer window in a corrupt state.
@ -511,7 +498,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
issueStreamError(
context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
context, remoteAddress, streamId, SpdyStreamStatus.INTERNAL_ERROR);
}
}
});
@ -521,15 +508,15 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
// Close the local side of the stream if this is the last frame
if (spdyDataFrame.isLast()) {
halfCloseStream(streamID, false);
halfCloseStream(streamId, false);
}
} else if (msg instanceof SpdySynStreamFrame) {
SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg;
int streamID = spdySynStreamFrame.getStreamId();
int streamId = spdySynStreamFrame.getStreamId();
if (isRemoteInitiatedID(streamID)) {
if (isRemoteInitiatedID(streamId)) {
e.getFuture().setFailure(PROTOCOL_EXCEPTION);
return;
}
@ -537,7 +524,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
byte priority = spdySynStreamFrame.getPriority();
boolean remoteSideClosed = spdySynStreamFrame.isUnidirectional();
boolean localSideClosed = spdySynStreamFrame.isLast();
if (!acceptStream(streamID, priority, remoteSideClosed, localSideClosed)) {
if (!acceptStream(streamId, priority, remoteSideClosed, localSideClosed)) {
e.getFuture().setFailure(PROTOCOL_EXCEPTION);
return;
}
@ -545,17 +532,17 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
} else if (msg instanceof SpdySynReplyFrame) {
SpdySynReplyFrame spdySynReplyFrame = (SpdySynReplyFrame) msg;
int streamID = spdySynReplyFrame.getStreamId();
int streamId = spdySynReplyFrame.getStreamId();
// Frames must not be sent on half-closed streams
if (!isRemoteInitiatedID(streamID) || spdySession.isLocalSideClosed(streamID)) {
if (!isRemoteInitiatedID(streamId) || spdySession.isLocalSideClosed(streamId)) {
e.getFuture().setFailure(PROTOCOL_EXCEPTION);
return;
}
// Close the local side of the stream if this is the last frame
if (spdySynReplyFrame.isLast()) {
halfCloseStream(streamID, false);
halfCloseStream(streamId, false);
}
} else if (msg instanceof SpdyRstStreamFrame) {
@ -609,17 +596,17 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
} else if (msg instanceof SpdyHeadersFrame) {
SpdyHeadersFrame spdyHeadersFrame = (SpdyHeadersFrame) msg;
int streamID = spdyHeadersFrame.getStreamId();
int streamId = spdyHeadersFrame.getStreamId();
// Frames must not be sent on half-closed streams
if (spdySession.isLocalSideClosed(streamID)) {
if (spdySession.isLocalSideClosed(streamId)) {
e.getFuture().setFailure(PROTOCOL_EXCEPTION);
return;
}
// Close the local side of the stream if this is the last frame
if (spdyHeadersFrame.isLast()) {
halfCloseStream(streamID, false);
halfCloseStream(streamId, false);
}
} else if (msg instanceof SpdyWindowUpdateFrame) {
@ -660,12 +647,12 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
* Note: this is only called by the worker thread
*/
private void issueStreamError(
ChannelHandlerContext ctx, SocketAddress remoteAddress, int streamID, SpdyStreamStatus status) {
ChannelHandlerContext ctx, SocketAddress remoteAddress, int streamId, SpdyStreamStatus status) {
boolean fireMessageReceived = !spdySession.isRemoteSideClosed(streamID);
removeStream(streamID);
boolean fireMessageReceived = !spdySession.isRemoteSideClosed(streamId);
removeStream(streamId);
SpdyRstStreamFrame spdyRstStreamFrame = new DefaultSpdyRstStreamFrame(streamID, status);
SpdyRstStreamFrame spdyRstStreamFrame = new DefaultSpdyRstStreamFrame(streamId, status);
Channels.write(ctx, Channels.future(ctx.getChannel()), spdyRstStreamFrame, remoteAddress);
if (fireMessageReceived) {
Channels.fireMessageReceived(ctx, spdyRstStreamFrame, remoteAddress);
@ -710,8 +697,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
private synchronized void updateInitialSendWindowSize(int newInitialWindowSize) {
int deltaWindowSize = newInitialWindowSize - initialSendWindowSize;
initialSendWindowSize = newInitialWindowSize;
for (Integer StreamID: spdySession.getActiveStreams()) {
spdySession.updateSendWindowSize(StreamID.intValue(), deltaWindowSize);
for (Integer StreamId: spdySession.getActiveStreams()) {
spdySession.updateSendWindowSize(StreamId.intValue(), deltaWindowSize);
}
}
@ -722,9 +709,9 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
spdySession.updateAllReceiveWindowSizes(deltaWindowSize);
}
// need to synchronize accesses to sentGoAwayFrame, lastGoodStreamID, and initial window sizes
// need to synchronize accesses to sentGoAwayFrame, lastGoodStreamId, and initial window sizes
private synchronized boolean acceptStream(
int streamID, byte priority, boolean remoteSideClosed, boolean localSideClosed) {
int streamId, byte priority, boolean remoteSideClosed, boolean localSideClosed) {
// Cannot initiate any new streams after receiving or sending GOAWAY
if (receivedGoAwayFrame || sentGoAwayFrame) {
return false;
@ -736,39 +723,39 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
return false;
}
spdySession.acceptStream(
streamID, priority, remoteSideClosed, localSideClosed,
streamId, priority, remoteSideClosed, localSideClosed,
initialSendWindowSize, initialReceiveWindowSize);
if (isRemoteInitiatedID(streamID)) {
lastGoodStreamID = streamID;
if (isRemoteInitiatedID(streamId)) {
lastGoodStreamId = streamId;
}
return true;
}
private void halfCloseStream(int streamID, boolean remote) {
private void halfCloseStream(int streamId, boolean remote) {
if (remote) {
spdySession.closeRemoteSide(streamID);
spdySession.closeRemoteSide(streamId);
} else {
spdySession.closeLocalSide(streamID);
spdySession.closeLocalSide(streamId);
}
if (closeSessionFuture != null && spdySession.noActiveStreams()) {
closeSessionFuture.setSuccess();
}
}
private void removeStream(int streamID) {
spdySession.removeStream(streamID);
private void removeStream(int streamId) {
spdySession.removeStream(streamId);
if (closeSessionFuture != null && spdySession.noActiveStreams()) {
closeSessionFuture.setSuccess();
}
}
private void updateSendWindowSize(ChannelHandlerContext ctx, final int streamID, int deltaWindowSize) {
private void updateSendWindowSize(ChannelHandlerContext ctx, final int streamId, int deltaWindowSize) {
synchronized (flowControlLock) {
int newWindowSize = spdySession.updateSendWindowSize(streamID, deltaWindowSize);
int newWindowSize = spdySession.updateSendWindowSize(streamId, deltaWindowSize);
while (newWindowSize > 0) {
// Check if we have unblocked a stalled stream
MessageEvent e = spdySession.getPendingWrite(streamID);
MessageEvent e = spdySession.getPendingWrite(streamId);
if (e == null) {
break;
}
@ -778,8 +765,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
if (newWindowSize >= dataFrameSize) {
// Window size is large enough to send entire data frame
spdySession.removePendingWrite(streamID);
newWindowSize = spdySession.updateSendWindowSize(streamID, -1 * dataFrameSize);
spdySession.removePendingWrite(streamId);
newWindowSize = spdySession.updateSendWindowSize(streamId, -1 * dataFrameSize);
// The transfer window size is pre-decremented when sending a data frame downstream.
// Close the stream on write failures that leaves the transfer window in a corrupt state.
@ -788,23 +775,23 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
e.getFuture().addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
issueStreamError(context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
issueStreamError(context, remoteAddress, streamId, SpdyStreamStatus.INTERNAL_ERROR);
}
}
});
// Close the local side of the stream if this is the last frame
if (spdyDataFrame.isLast()) {
halfCloseStream(streamID, false);
halfCloseStream(streamId, false);
}
Channels.write(ctx, e.getFuture(), spdyDataFrame, e.getRemoteAddress());
} else {
// We can send a partial frame
spdySession.updateSendWindowSize(streamID, -1 * newWindowSize);
spdySession.updateSendWindowSize(streamId, -1 * newWindowSize);
// Create a partial data frame whose length is the current window size
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamID);
SpdyDataFrame partialDataFrame = new DefaultSpdyDataFrame(streamId);
partialDataFrame.setData(spdyDataFrame.getData().readSlice(newWindowSize));
ChannelFuture writeFuture = Channels.future(e.getChannel());
@ -816,7 +803,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
e.getFuture().addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
issueStreamError(context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
issueStreamError(context, remoteAddress, streamId, SpdyStreamStatus.INTERNAL_ERROR);
}
}
});
@ -849,7 +836,7 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, SpdySessionStatus status) {
if (!sentGoAwayFrame) {
sentGoAwayFrame = true;
SpdyGoAwayFrame spdyGoAwayFrame = new DefaultSpdyGoAwayFrame(lastGoodStreamID, status);
SpdyGoAwayFrame spdyGoAwayFrame = new DefaultSpdyGoAwayFrame(lastGoodStreamId, status);
ChannelFuture future = Channels.future(channel);
Channels.write(ctx, future, spdyGoAwayFrame, remoteAddress);
return future;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -18,9 +18,9 @@ package org.jboss.netty.handler.codec.spdy;
import java.util.Set;
/**
* A SPDY Protocol SETTINGS Control Frame
* A SPDY Protocol SETTINGS Frame
*/
public interface SpdySettingsFrame {
public interface SpdySettingsFrame extends SpdyFrame {
int SETTINGS_UPLOAD_BANDWIDTH = 1;
int SETTINGS_DOWNLOAD_BANDWIDTH = 2;
@ -31,12 +31,6 @@ public interface SpdySettingsFrame {
int SETTINGS_INITIAL_WINDOW_SIZE = 7;
int SETTINGS_CLIENT_CERTIFICATE_VECTOR_SIZE = 8;
/**
* @deprecated Use {@link #getIds()} instead.
*/
@Deprecated
Set<Integer> getIDs();
/**
* Returns a {@code Set} of the setting IDs.
* The set's iterator will return the IDs in ascending order.
@ -70,16 +64,10 @@ public interface SpdySettingsFrame {
/**
* Removes the value of the setting ID.
* Removes all persistance information for the setting.
* Removes all persistence information for the setting.
*/
void removeValue(int id);
/**
* @deprecated Use {@link #isPersistValue(int)} instead.
*/
@Deprecated
boolean persistValue(int id);
/**
* Returns {@code true} if this setting should be persisted.
* Returns {@code false} if this setting should not be persisted

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,12 +16,28 @@
package org.jboss.netty.handler.codec.spdy;
/**
* The default {@link SpdyNoOpFrame} implementation.
* A SPDY Protocol Frame that is associated with an individual SPDY Stream
*/
public class DefaultSpdyNoOpFrame implements SpdyNoOpFrame {
public interface SpdyStreamFrame extends SpdyFrame {
@Override
public String toString() {
return getClass().getSimpleName();
}
/**
* Returns the Stream-ID of this frame.
*/
int getStreamId();
/**
* Sets the Stream-ID of this frame. The Stream-ID must be positive.
*/
void setStreamId(int streamId);
/**
* Returns {@code true} if this frame is the last frame to be transmitted
* on the stream.
*/
boolean isLast();
/**
* Sets if this frame is the last frame to be transmitted on the stream.
*/
void setLast(boolean last);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,40 +16,8 @@
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol SYN_REPLY Control Frame
* A SPDY Protocol SYN_REPLY Frame
*/
public interface SpdySynReplyFrame extends SpdyHeaderBlock {
/**
* @deprecated Use {@link #getStreamId()} instead.
*/
@Deprecated
int getStreamID();
/**
* Returns the Stream-ID of this frame.
*/
int getStreamId();
/**
* @deprecated Use {@link #setStreamId(int)} instead.
*/
@Deprecated
void setStreamID(int streamID);
/**
* Sets the Stream-ID of this frame. The Stream-ID must be positive.
*/
void setStreamId(int streamID);
/**
* Returns {@code true} if this frame is the last frame to be transmitted
* on the stream.
*/
boolean isLast();
/**
* Sets if this frame is the last frame to be transmitted on the stream.
*/
void setLast(boolean last);
public interface SpdySynReplyFrame extends SpdyHeadersFrame {
// Tag interface
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,49 +16,15 @@
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol SYN_STREAM Control Frame
* A SPDY Protocol SYN_STREAM Frame
*/
public interface SpdySynStreamFrame extends SpdyHeaderBlock {
/**
* @deprecated Use {@link #getStreamId()} instead.
*/
@Deprecated
int getStreamID();
/**
* Returns the Stream-ID of this frame.
*/
int getStreamId();
/**
* @deprecated Use {@link #setStreamId(int)} instead.
*/
@Deprecated
void setStreamID(int streamID);
/**
* Sets the Stream-ID of this frame. The Stream-ID must be positive.
*/
void setStreamId(int streamId);
/**
* @deprecated Use {@link #getAssociatedToStreamId()} instead.
*/
@Deprecated
int getAssociatedToStreamID();
public interface SpdySynStreamFrame extends SpdyHeadersFrame {
/**
* Returns the Associated-To-Stream-ID of this frame.
*/
int getAssociatedToStreamId();
/**
* @deprecated Use {@link #setAssociatedToStreamId(int)} instead.
*/
@Deprecated
void setAssociatedToStreamID(int associatedToStreamId);
/**
* Sets the Associated-To-Stream-ID of this frame.
* The Associated-To-Stream-ID cannot be negative.
@ -76,17 +42,6 @@ public interface SpdySynStreamFrame extends SpdyHeaderBlock {
*/
void setPriority(byte priority);
/**
* Returns {@code true} if this frame is the last frame to be transmitted
* on the stream.
*/
boolean isLast();
/**
* Sets if this frame is the last frame to be transmitted on the stream.
*/
void setLast(boolean last);
/**
* Returns {@code true} if the stream created with this frame is to be
* considered half-closed to the receiver.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -16,15 +16,9 @@
package org.jboss.netty.handler.codec.spdy;
/**
* A SPDY Protocol WINDOW_UPDATE Control Frame
* A SPDY Protocol WINDOW_UPDATE Frame
*/
public interface SpdyWindowUpdateFrame {
/**
* @deprecated Use {@link #getStreamId()} instead.
*/
@Deprecated
int getStreamID();
public interface SpdyWindowUpdateFrame extends SpdyFrame {
/**
* Returns the Stream-ID of this frame.
@ -32,12 +26,7 @@ public interface SpdyWindowUpdateFrame {
int getStreamId();
/**
* Use {@link #setStreamId(int)} instead.
*/
void setStreamID(int streamId);
/**
* Sets the Stream-ID of this frame. The Stream-ID must be positive.
* Sets the Stream-ID of this frame. The Stream-ID cannot be negative.
*/
void setStreamId(int streamId);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 The Netty Project
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
@ -38,40 +38,25 @@ public class SpdySessionHandlerTest {
closeMessage.setValue(closeSignal, 0);
}
private static void assertHeaderBlock(SpdyHeaderBlock received, SpdyHeaderBlock expected) {
for (String name: expected.getHeaderNames()) {
List<String> expectedValues = expected.getHeaders(name);
List<String> receivedValues = received.getHeaders(name);
assertTrue(receivedValues.containsAll(expectedValues));
receivedValues.removeAll(expectedValues);
assertTrue(receivedValues.isEmpty());
received.removeHeader(name);
}
assertTrue(received.getHeaders().isEmpty());
}
private static void assertDataFrame(Object msg, int streamID, boolean last) {
private static void assertDataFrame(Object msg, int streamId, boolean last) {
assertNotNull(msg);
assertTrue(msg instanceof SpdyDataFrame);
SpdyDataFrame spdyDataFrame = (SpdyDataFrame) msg;
assertEquals(spdyDataFrame.getStreamId(), streamID);
assertEquals(spdyDataFrame.getStreamId(), streamId);
assertEquals(spdyDataFrame.isLast(), last);
}
private static void assertSynReply(Object msg, int streamID, boolean last, SpdyHeaderBlock headers) {
private static void assertSynReply(Object msg, int streamId, boolean last, SpdyHeadersFrame headers) {
assertNotNull(msg);
assertTrue(msg instanceof SpdySynReplyFrame);
SpdySynReplyFrame spdySynReplyFrame = (SpdySynReplyFrame) msg;
assertEquals(spdySynReplyFrame.getStreamId(), streamID);
assertEquals(spdySynReplyFrame.isLast(), last);
assertHeaderBlock(spdySynReplyFrame, headers);
assertHeaders(msg, streamId, last, headers);
}
private static void assertRstStream(Object msg, int streamID, SpdyStreamStatus status) {
private static void assertRstStream(Object msg, int streamId, SpdyStreamStatus status) {
assertNotNull(msg);
assertTrue(msg instanceof SpdyRstStreamFrame);
SpdyRstStreamFrame spdyRstStreamFrame = (SpdyRstStreamFrame) msg;
assertEquals(spdyRstStreamFrame.getStreamId(), streamID);
assertEquals(spdyRstStreamFrame.getStreamId(), streamId);
assertEquals(spdyRstStreamFrame.getStatus(), status);
}
@ -82,19 +67,28 @@ public class SpdySessionHandlerTest {
assertEquals(spdyPingFrame.getId(), id);
}
private static void assertGoAway(Object msg, int lastGoodStreamID) {
private static void assertGoAway(Object msg, int lastGoodStreamId) {
assertNotNull(msg);
assertTrue(msg instanceof SpdyGoAwayFrame);
SpdyGoAwayFrame spdyGoAwayFrame = (SpdyGoAwayFrame) msg;
assertEquals(spdyGoAwayFrame.getLastGoodStreamId(), lastGoodStreamID);
assertEquals(spdyGoAwayFrame.getLastGoodStreamId(), lastGoodStreamId);
}
private static void assertHeaders(Object msg, int streamID, SpdyHeaderBlock headers) {
private static void assertHeaders(Object msg, int streamId, boolean last, SpdyHeadersFrame headers) {
assertNotNull(msg);
assertTrue(msg instanceof SpdyHeadersFrame);
SpdyHeadersFrame spdyHeadersFrame = (SpdyHeadersFrame) msg;
assertEquals(spdyHeadersFrame.getStreamId(), streamID);
assertHeaderBlock(spdyHeadersFrame, headers);
assertEquals(spdyHeadersFrame.getStreamId(), streamId);
assertEquals(spdyHeadersFrame.isLast(), last);
for (String name: headers.getHeaderNames()) {
List<String> expectedValues = headers.getHeaders(name);
List<String> receivedValues = spdyHeadersFrame.getHeaders(name);
assertTrue(receivedValues.containsAll(expectedValues));
receivedValues.removeAll(expectedValues);
assertTrue(receivedValues.isEmpty());
spdyHeadersFrame.removeHeader(name);
}
assertTrue(spdyHeadersFrame.getHeaders().isEmpty());
}
private static void testSpdySessionHandler(int version, boolean server) {
@ -103,68 +97,68 @@ public class SpdySessionHandlerTest {
new SpdySessionHandler(version, server), new EchoHandler(closeSignal, server));
sessionHandler.pollAll();
int localStreamID = server ? 1 : 2;
int remoteStreamID = server ? 2 : 1;
int localStreamId = server ? 1 : 2;
int remoteStreamId = server ? 2 : 1;
SpdyPingFrame localPingFrame = new DefaultSpdyPingFrame(localStreamID);
SpdyPingFrame remotePingFrame = new DefaultSpdyPingFrame(remoteStreamID);
SpdyPingFrame localPingFrame = new DefaultSpdyPingFrame(localStreamId);
SpdyPingFrame remotePingFrame = new DefaultSpdyPingFrame(remoteStreamId);
SpdySynStreamFrame spdySynStreamFrame =
new DefaultSpdySynStreamFrame(localStreamID, 0, (byte) 0);
new DefaultSpdySynStreamFrame(localStreamId, 0, (byte) 0);
spdySynStreamFrame.setHeader("Compression", "test");
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(localStreamID);
SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(localStreamId);
spdyDataFrame.setLast(true);
// Check if session handler returns INVALID_STREAM if it receives
// a data frame for a Stream-ID that is not open
sessionHandler.offer(new DefaultSpdyDataFrame(localStreamID));
assertRstStream(sessionHandler.poll(), localStreamID, SpdyStreamStatus.INVALID_STREAM);
sessionHandler.offer(new DefaultSpdyDataFrame(localStreamId));
assertRstStream(sessionHandler.poll(), localStreamId, SpdyStreamStatus.INVALID_STREAM);
assertNull(sessionHandler.peek());
// Check if session handler returns PROTOCOL_ERROR if it receives
// a data frame for a Stream-ID before receiving a SYN_REPLY frame
sessionHandler.offer(new DefaultSpdyDataFrame(remoteStreamID));
assertRstStream(sessionHandler.poll(), remoteStreamID, SpdyStreamStatus.PROTOCOL_ERROR);
sessionHandler.offer(new DefaultSpdyDataFrame(remoteStreamId));
assertRstStream(sessionHandler.poll(), remoteStreamId, SpdyStreamStatus.PROTOCOL_ERROR);
assertNull(sessionHandler.peek());
remoteStreamID += 2;
remoteStreamId += 2;
// Check if session handler returns PROTOCOL_ERROR if it receives
// multiple SYN_REPLY frames for the same active Stream-ID
sessionHandler.offer(new DefaultSpdySynReplyFrame(remoteStreamID));
sessionHandler.offer(new DefaultSpdySynReplyFrame(remoteStreamId));
assertNull(sessionHandler.peek());
sessionHandler.offer(new DefaultSpdySynReplyFrame(remoteStreamID));
assertRstStream(sessionHandler.poll(), remoteStreamID, SpdyStreamStatus.STREAM_IN_USE);
sessionHandler.offer(new DefaultSpdySynReplyFrame(remoteStreamId));
assertRstStream(sessionHandler.poll(), remoteStreamId, SpdyStreamStatus.STREAM_IN_USE);
assertNull(sessionHandler.peek());
remoteStreamID += 2;
remoteStreamId += 2;
// Check if frame codec correctly compresses/uncompresses headers
sessionHandler.offer(spdySynStreamFrame);
assertSynReply(sessionHandler.poll(), localStreamID, false, spdySynStreamFrame);
assertSynReply(sessionHandler.poll(), localStreamId, false, spdySynStreamFrame);
assertNull(sessionHandler.peek());
SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(localStreamID);
SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(localStreamId);
spdyHeadersFrame.addHeader("HEADER","test1");
spdyHeadersFrame.addHeader("HEADER","test2");
sessionHandler.offer(spdyHeadersFrame);
assertHeaders(sessionHandler.poll(), localStreamID, spdyHeadersFrame);
assertHeaders(sessionHandler.poll(), localStreamId, false, spdyHeadersFrame);
assertNull(sessionHandler.peek());
localStreamID += 2;
localStreamId += 2;
// Check if session handler closed the streams using the number
// of concurrent streams and that it returns REFUSED_STREAM
// if it receives a SYN_STREAM frame it does not wish to accept
spdySynStreamFrame.setStreamId(localStreamID);
spdySynStreamFrame.setStreamId(localStreamId);
spdySynStreamFrame.setLast(true);
spdySynStreamFrame.setUnidirectional(true);
sessionHandler.offer(spdySynStreamFrame);
assertRstStream(sessionHandler.poll(), localStreamID, SpdyStreamStatus.REFUSED_STREAM);
assertRstStream(sessionHandler.poll(), localStreamId, SpdyStreamStatus.REFUSED_STREAM);
assertNull(sessionHandler.peek());
// Check if session handler drops active streams if it receives
// a RST_STREAM frame for that Stream-ID
sessionHandler.offer(new DefaultSpdyRstStreamFrame(remoteStreamID, 3));
sessionHandler.offer(new DefaultSpdyRstStreamFrame(remoteStreamId, 3));
assertNull(sessionHandler.peek());
remoteStreamID += 2;
remoteStreamId += 2;
// Check if session handler honors UNIDIRECTIONAL streams
spdySynStreamFrame.setLast(false);
@ -175,17 +169,17 @@ public class SpdySessionHandlerTest {
// Check if session handler returns PROTOCOL_ERROR if it receives
// multiple SYN_STREAM frames for the same active Stream-ID
sessionHandler.offer(spdySynStreamFrame);
assertRstStream(sessionHandler.poll(), localStreamID, SpdyStreamStatus.PROTOCOL_ERROR);
assertRstStream(sessionHandler.poll(), localStreamId, SpdyStreamStatus.PROTOCOL_ERROR);
assertNull(sessionHandler.peek());
localStreamID += 2;
localStreamId += 2;
// Check if session handler returns PROTOCOL_ERROR if it receives
// a SYN_STREAM frame with an invalid Stream-ID
spdySynStreamFrame.setStreamId(localStreamID - 1);
spdySynStreamFrame.setStreamId(localStreamId - 1);
sessionHandler.offer(spdySynStreamFrame);
assertRstStream(sessionHandler.poll(), localStreamID - 1, SpdyStreamStatus.PROTOCOL_ERROR);
assertRstStream(sessionHandler.poll(), localStreamId - 1, SpdyStreamStatus.PROTOCOL_ERROR);
assertNull(sessionHandler.peek());
spdySynStreamFrame.setStreamId(localStreamID);
spdySynStreamFrame.setStreamId(localStreamId);
// Check if session handler correctly limits the number of
// concurrent streams in the SETTINGS frame
@ -194,31 +188,31 @@ public class SpdySessionHandlerTest {
sessionHandler.offer(spdySettingsFrame);
assertNull(sessionHandler.peek());
sessionHandler.offer(spdySynStreamFrame);
assertRstStream(sessionHandler.poll(), localStreamID, SpdyStreamStatus.REFUSED_STREAM);
assertRstStream(sessionHandler.poll(), localStreamId, SpdyStreamStatus.REFUSED_STREAM);
assertNull(sessionHandler.peek());
spdySettingsFrame.setValue(SpdySettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS, 4);
sessionHandler.offer(spdySettingsFrame);
assertNull(sessionHandler.peek());
sessionHandler.offer(spdySynStreamFrame);
assertSynReply(sessionHandler.poll(), localStreamID, false, spdySynStreamFrame);
assertSynReply(sessionHandler.poll(), localStreamId, false, spdySynStreamFrame);
assertNull(sessionHandler.peek());
// Check if session handler rejects HEADERS for closed streams
int testStreamID = spdyDataFrame.getStreamId();
int testStreamId = spdyDataFrame.getStreamId();
sessionHandler.offer(spdyDataFrame);
assertDataFrame(sessionHandler.poll(), testStreamID, spdyDataFrame.isLast());
assertDataFrame(sessionHandler.poll(), testStreamId, spdyDataFrame.isLast());
assertNull(sessionHandler.peek());
spdyHeadersFrame.setStreamId(testStreamID);
spdyHeadersFrame.setStreamId(testStreamId);
sessionHandler.offer(spdyHeadersFrame);
assertRstStream(sessionHandler.poll(), testStreamID, SpdyStreamStatus.INVALID_STREAM);
assertRstStream(sessionHandler.poll(), testStreamId, SpdyStreamStatus.INVALID_STREAM);
assertNull(sessionHandler.peek());
// Check if session handler returns PROTOCOL_ERROR if it receives
// an invalid HEADERS frame
spdyHeadersFrame.setStreamId(localStreamID);
spdyHeadersFrame.setStreamId(localStreamId);
spdyHeadersFrame.setInvalid();
sessionHandler.offer(spdyHeadersFrame);
assertRstStream(sessionHandler.poll(), localStreamID, SpdyStreamStatus.PROTOCOL_ERROR);
assertRstStream(sessionHandler.poll(), localStreamId, SpdyStreamStatus.PROTOCOL_ERROR);
assertNull(sessionHandler.peek());
// Check if session handler returns identical local PINGs
@ -232,20 +226,20 @@ public class SpdySessionHandlerTest {
// Check if session handler sends a GOAWAY frame when closing
sessionHandler.offer(closeMessage);
assertGoAway(sessionHandler.poll(), localStreamID);
assertGoAway(sessionHandler.poll(), localStreamId);
assertNull(sessionHandler.peek());
localStreamID += 2;
localStreamId += 2;
// Check if session handler returns REFUSED_STREAM if it receives
// SYN_STREAM frames after sending a GOAWAY frame
spdySynStreamFrame.setStreamId(localStreamID);
spdySynStreamFrame.setStreamId(localStreamId);
sessionHandler.offer(spdySynStreamFrame);
assertRstStream(sessionHandler.poll(), localStreamID, SpdyStreamStatus.REFUSED_STREAM);
assertRstStream(sessionHandler.poll(), localStreamId, SpdyStreamStatus.REFUSED_STREAM);
assertNull(sessionHandler.peek());
// Check if session handler ignores Data frames after sending
// a GOAWAY frame
spdyDataFrame.setStreamId(localStreamID);
spdyDataFrame.setStreamId(localStreamId);
sessionHandler.offer(spdyDataFrame);
assertNull(sessionHandler.peek());
@ -282,9 +276,9 @@ public class SpdySessionHandlerTest {
throws Exception {
// Initiate 4 new streams
int streamID = server ? 2 : 1;
int streamId = server ? 2 : 1;
SpdySynStreamFrame spdySynStreamFrame =
new DefaultSpdySynStreamFrame(streamID, 0, (byte) 0);
new DefaultSpdySynStreamFrame(streamId, 0, (byte) 0);
spdySynStreamFrame.setLast(true);
Channels.write(e.getChannel(), spdySynStreamFrame);
spdySynStreamFrame.setStreamId(spdySynStreamFrame.getStreamId() + 2);
@ -304,20 +298,12 @@ public class SpdySessionHandlerTest {
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
Object msg = e.getMessage();
if (msg instanceof SpdyDataFrame ||
msg instanceof SpdyPingFrame ||
msg instanceof SpdyHeadersFrame) {
Channels.write(e.getChannel(), msg, e.getRemoteAddress());
return;
}
if (msg instanceof SpdySynStreamFrame) {
SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg;
int streamID = spdySynStreamFrame.getStreamId();
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamID);
int streamId = spdySynStreamFrame.getStreamId();
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamId);
spdySynReplyFrame.setLast(spdySynStreamFrame.isLast());
for (Map.Entry<String, String> entry: spdySynStreamFrame.getHeaders()) {
spdySynReplyFrame.addHeader(entry.getKey(), entry.getValue());
@ -327,6 +313,18 @@ public class SpdySessionHandlerTest {
return;
}
if (msg instanceof SpdySynReplyFrame) {
return;
}
if (msg instanceof SpdyDataFrame ||
msg instanceof SpdyPingFrame ||
msg instanceof SpdyHeadersFrame) {
Channels.write(e.getChannel(), msg, e.getRemoteAddress());
return;
}
if (msg instanceof SpdySettingsFrame) {
SpdySettingsFrame spdySettingsFrame = (SpdySettingsFrame) msg;