Search in sources :

Example 11 with SendFrameHeader

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;
}
Also used : SendFrameHeader(io.undertow.server.protocol.framed.SendFrameHeader)

Example 12 with SendFrameHeader

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));
}
Also used : ImmediatePooledByteBuffer(io.undertow.util.ImmediatePooledByteBuffer) ByteBuffer(java.nio.ByteBuffer) SendFrameHeader(io.undertow.server.protocol.framed.SendFrameHeader) ImmediatePooledByteBuffer(io.undertow.util.ImmediatePooledByteBuffer)

Example 13 with SendFrameHeader

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));
}
Also used : ImmediatePooledByteBuffer(io.undertow.util.ImmediatePooledByteBuffer) PooledByteBuffer(io.undertow.connector.PooledByteBuffer) ByteBuffer(java.nio.ByteBuffer) SendFrameHeader(io.undertow.server.protocol.framed.SendFrameHeader) ImmediatePooledByteBuffer(io.undertow.util.ImmediatePooledByteBuffer)

Aggregations

SendFrameHeader (io.undertow.server.protocol.framed.SendFrameHeader)13 ByteBuffer (java.nio.ByteBuffer)8 ImmediatePooledByteBuffer (io.undertow.util.ImmediatePooledByteBuffer)7 PooledByteBuffer (io.undertow.connector.PooledByteBuffer)4 AjpUtils.putString (io.undertow.protocols.ajp.AjpUtils.putString)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 BufferOverflowException (java.nio.BufferOverflowException)1