if (!checkConnection(http)) {
return;
}
MultiMap mimeHeaders = http.getRequest().getMimeHeaders();
BBuffer headBuf = BBuffer.allocate();
SpdyConnection.appendShort(headBuf, mimeHeaders.size() + 3);
serializeMime(mimeHeaders, headBuf);
// TODO: url - with host prefix , method
// optimize...
SpdyConnection.appendAsciiHead(headBuf, "version");
SpdyConnection.appendAsciiHead(headBuf, "HTTP/1.1");
SpdyConnection.appendAsciiHead(headBuf, "method");
SpdyConnection.appendAsciiHead(headBuf, http.getRequest().getMethod());
SpdyConnection.appendAsciiHead(headBuf, "url");
// TODO: url
SpdyConnection.appendAsciiHead(headBuf, http.getRequest().requestURL());
if (headerCompression && httpConnector.compression) {
headerCompressBuffer.recycle();
headCompressOut.compress(headBuf, headerCompressBuffer, false);
headBuf.recycle();
headerCompressBuffer.copyAll(headBuf);
}
// Frame head - 8
BBuffer out = BBuffer.allocate();
// Syn-reply
out.putByte(0x80);
out.putByte(0x01);
out.putByte(0x00);
out.putByte(0x01);
CBuffer method = http.getRequest().method();
if (method.equals("GET") || method.equals("HEAD")) {
http.getOut().close();
}
if (http.getOut().isAppendClosed()) {
out.putByte(0x01); // closed
} else {
out.putByte(0x00);
}
// Length, channel id (4) + unused (2) - headBuf has header count
// and headers
SpdyConnection.append24(out, headBuf.remaining() + 6);
if (serverMode) {
http.channelId = 2 * lastOutStream.incrementAndGet();
} else {
http.channelId = 2 * lastOutStream.incrementAndGet() + 1;
}
SpdyConnection.appendInt(out, http.channelId);
http.setConnection(this);
synchronized (channels) {
channels.put(http.channelId, http);
}
out.putByte(0x00); // no priority
out.putByte(0x00);
sendFrame(out, headBuf);
if (http.outMessage.state == HttpMessage.State.HEAD) {
http.outMessage.state = HttpMessage.State.BODY_DATA;