package io.undertow.protocols.http2;
import java.nio.ByteBuffer;
import java.util.List;
import io.undertow.connector.PooledByteBuffer;
import io.undertow.server.protocol.framed.SendFrameHeader;
public class Http2SettingsStreamSinkChannel extends Http2StreamSinkChannel {
private final List<Http2Setting> settings;
Http2SettingsStreamSinkChannel(Http2Channel channel, List<Http2Setting> settings) {
super(channel, 0);
this.settings = settings;
}
Http2SettingsStreamSinkChannel(Http2Channel channel) {
super(channel, 0);
this.settings = null;
}
@Override
protected SendFrameHeader () {
PooledByteBuffer pooled = getChannel().getBufferPool().allocate();
ByteBuffer currentBuffer = pooled.getBuffer();
if (settings != null) {
int size = settings.size() * 6;
currentBuffer.put((byte) ((size >> 16) & 0xFF));
currentBuffer.put((byte) ((size >> 8) & 0xFF));
currentBuffer.put((byte) (size & 0xFF));
currentBuffer.put((byte) Http2Channel.FRAME_TYPE_SETTINGS);
currentBuffer.put((byte) 0);
Http2ProtocolUtils.putInt(currentBuffer, getStreamId());
for (Http2Setting setting : settings) {
currentBuffer.put((byte) ((setting.getId() >> 8) & 0xFF));
currentBuffer.put((byte) (setting.getId() & 0xFF));
currentBuffer.put((byte) ((setting.getValue() >> 24) & 0xFF));
currentBuffer.put((byte) ((setting.getValue() >> 16) & 0xFF));
currentBuffer.put((byte) ((setting.getValue() >> 8) & 0xFF));
currentBuffer.put((byte) (setting.getValue() & 0xFF));
}
} else {
currentBuffer.put((byte) 0);
currentBuffer.put((byte) 0);
currentBuffer.put((byte) 0);
currentBuffer.put((byte) Http2Channel.FRAME_TYPE_SETTINGS);
currentBuffer.put((byte) Http2Channel.SETTINGS_FLAG_ACK);
Http2ProtocolUtils.putInt(currentBuffer, getStreamId());
}
currentBuffer.flip();
return new SendFrameHeader(pooled);
}
}