@@ -0,0 +1,2492 @@
+/*%0A * Copyright 2012 The Netty Project%0A *%0A * The Netty Project licenses this file to you under the Apache License,%0A * version 2.0 (the %22License%22); you may not use this file except in compliance%0A * with the License. You may obtain a copy of the License at:%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations%0A * under the License.%0A */%0Apackage org.jboss.netty.handler.codec.spdy;%0A%0Aimport java.util.Queue;%0Aimport java.util.concurrent.ConcurrentLinkedQueue;%0A%0Aimport org.jboss.netty.channel.ChannelHandlerContext;%0Aimport org.jboss.netty.channel.MessageEvent;%0Aimport org.jboss.netty.channel.SimpleChannelHandler;%0Aimport org.jboss.netty.handler.codec.http.HttpMessage;%0Aimport org.jboss.netty.handler.codec.http.HttpResponse;%0A%0A/**%0A * %7B@link SimpleChannelHandler%7D which will take care of add the right %7B@link SpdyHttpHeaders#Names#STREAM_ID%7D to the%0A * %7B@link HttpResponse%7D if non is in there. This makes it possible to just re-use plan handlers that was used with HTTP%0A * only before.%0A *%0A */%0Apublic class SpdyHttpResponseStreamIdHandler extends SimpleChannelHandler %7B%0A    private static final Integer NO_ID = -1;%0A    private final Queue%3CInteger%3E ids = new ConcurrentLinkedQueue%3CInteger%3E();%0A%0A    @Override%0A    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception %7B%0A        if (e.getMessage() instanceof HttpMessage) %7B%0A            boolean contains = ((HttpMessage) e.getMessage()).containsHeader(SpdyHttpHeaders.Names.STREAM_ID);%0A            if (!contains) %7B%0A                ids.add(NO_ID);%0A            %7D else %7B%0A                ids.add(SpdyHttpHeaders.getStreamId((HttpMessage) e.getMessage()));%0A            %7D%0A        %7D%0A        super.messageReceived(ctx, e);%0A    %7D%0A%0A    @Override%0A    public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception %7B%0A        if (e.getMessage() instanceof HttpResponse) %7B%0A            HttpResponse response = (HttpResponse) e.getMessage();%0A            Integer id = ids.poll();%0A            if (id != null && id != NO_ID && !response.containsHeader(SpdyHttpHeaders.Names.STREAM_ID)) %7B%0A                SpdyHttpHeaders.setStreamId(response, id);%0A            %7D%0A        %7D%0A        super.writeRequested(ctx, e);%0A    %7D%0A%0A%7D%0A

Add a new handler which is called SpdyHttpResponseStreamIdHandler and takes care of adding the right STREAM_ID if non is present. This makes it possible to reuse http only handlers with spdy. See #626