use of io.undertow.server.protocol.framed.SendFrameHeader in project undertow by undertow-io.
the class Http2StreamSinkChannel method createFrameHeader.
@Override
protected final SendFrameHeader createFrameHeader() {
SendFrameHeader header = this.header;
this.header = null;
return header;
}
use of io.undertow.server.protocol.framed.SendFrameHeader in project undertow by undertow-io.
the class Http2WindowUpdateStreamSinkChannel method createFrameHeader.
@Override
protected SendFrameHeader createFrameHeader() {
ByteBuffer buf = ByteBuffer.allocate(13);
Http2ProtocolUtils.putInt(buf, HEADER_FIRST_LINE);
buf.put((byte) 0);
Http2ProtocolUtils.putInt(buf, streamId);
Http2ProtocolUtils.putInt(buf, deltaWindowSize);
buf.flip();
return new SendFrameHeader(new ImmediatePooledByteBuffer(buf));
}
use of io.undertow.server.protocol.framed.SendFrameHeader in project undertow by undertow-io.
the class WebSocket07FrameSinkChannel method createFrameHeader.
@Override
protected SendFrameHeader createFrameHeader() {
byte b0 = 0;
//if writes are shutdown this is the final fragment
if (isFinalFrameQueued()) {
// set FIN
b0 |= 1 << 7;
}
/*
Known extensions (i.e. compression) should not modify RSV bit on continuation bit.
*/
byte opCode = opCode();
int rsv = opCode == WebSocket07Channel.OPCODE_CONT ? 0 : getRsv();
b0 |= (rsv & 7) << 4;
b0 |= opCode & 0xf;
final ByteBuffer header = ByteBuffer.allocate(14);
byte maskKey = 0;
if (masker != null) {
maskKey |= 1 << 7;
}
long payloadSize = getBuffer().remaining();
if (payloadSize > 125 && opCode == WebSocket07Channel.OPCODE_PING) {
throw WebSocketMessages.MESSAGES.invalidPayloadLengthForPing(payloadSize);
}
if (payloadSize <= 125) {
header.put(b0);
header.put((byte) ((payloadSize | maskKey) & 0xFF));
} else if (payloadSize <= 0xFFFF) {
header.put(b0);
header.put((byte) ((126 | maskKey) & 0xFF));
header.put((byte) (payloadSize >>> 8 & 0xFF));
header.put((byte) (payloadSize & 0xFF));
} else {
header.put(b0);
header.put((byte) ((127 | maskKey) & 0xFF));
header.putLong(payloadSize);
}
if (masker != null) {
//generate a new key for this frame
int maskingKey = random.nextInt();
header.put((byte) ((maskingKey >> 24) & 0xFF));
header.put((byte) ((maskingKey >> 16) & 0xFF));
header.put((byte) ((maskingKey >> 8) & 0xFF));
header.put((byte) ((maskingKey & 0xFF)));
masker.setMaskingKey(maskingKey);
//do any required masking
ByteBuffer buf = getBuffer();
masker.beforeWrite(buf, buf.position(), buf.remaining());
}
header.flip();
return new SendFrameHeader(0, new ImmediatePooledByteBuffer(header));
}
Aggregations