Example #1
0
  private SpdySynReplyFrame createSynReplyFrame(HttpResponse httpResponse) throws Exception {
    boolean chunked = httpResponse.isChunked();

    // Get the Stream-ID from the headers
    int streamID = SpdyHttpHeaders.getStreamID(httpResponse);
    SpdyHttpHeaders.removeStreamID(httpResponse);

    // 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");
    httpResponse.removeHeader("Proxy-Connection");
    httpResponse.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);

    SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamID);

    // Unfold the first line of the response into name/value pairs
    SpdyHeaders.setStatus(spdyVersion, spdySynReplyFrame, httpResponse.getStatus());
    SpdyHeaders.setVersion(spdyVersion, spdySynReplyFrame, httpResponse.getProtocolVersion());

    // Transfer the remaining HTTP headers
    for (Map.Entry<String, String> entry : httpResponse.getHeaders()) {
      spdySynReplyFrame.addHeader(entry.getKey(), entry.getValue());
    }

    if (chunked) {
      currentStreamID = streamID;
      spdySynReplyFrame.setLast(false);
    } else {
      spdySynReplyFrame.setLast(httpResponse.getContent().readableBytes() == 0);
    }

    return spdySynReplyFrame;
  }