Search in sources :

Example 1 with Http2Frame

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame in project webpieces by deanhiller.

the class TestS4FrameSizeAndHeaders method createInterleavedFrames.

private List<Http2Frame> createInterleavedFrames() {
    Http2Response response1 = new Http2Response();
    response1.setStreamId(1);
    response1.setEndOfStream(true);
    fillHeaders(response1);
    HeaderEncoding encoding = new HeaderEncoding();
    List<Http2Frame> frames1 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response1);
    Http2Response response2 = new Http2Response();
    response2.setStreamId(3);
    response1.setEndOfStream(true);
    response2.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "value"));
    List<Http2Frame> frames2 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response2);
    List<Http2Frame> frames = new ArrayList<>();
    frames.addAll(frames1);
    frames.add(1, frames2.get(0));
    return frames;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) HeaderEncoding(com.webpieces.hpack.impl.HeaderEncoding) Encoder(com.twitter.hpack.Encoder) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Example 2 with Http2Frame

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame in project webpieces by deanhiller.

the class SettingsMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("SettingsFrame can never be any other stream id except 0 which is already set");
    SettingsFrame castFrame = (SettingsFrame) frame;
    for (Http2Setting setting : castFrame.getSettings()) {
        validate(setting);
    }
    byte flags = 0x0;
    if (castFrame.isAck())
        flags |= 0x1;
    DataWrapper dataPayload;
    if (castFrame.isAck()) {
        if (castFrame.getSettings() != null && castFrame.getSettings().size() > 0)
            throw new IllegalArgumentException("Ack SettingsFrame can not have setting in it");
        dataPayload = DATA_GEN.emptyWrapper();
    } else if (castFrame.getSettings().size() == 0) {
        dataPayload = DATA_GEN.emptyWrapper();
    } else {
        List<Http2Setting> settings = castFrame.getSettings();
        dataPayload = marshalOut(settings);
    }
    return super.marshalFrame(frame, flags, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) SettingsFrame(com.webpieces.http2.api.dto.lowlevel.SettingsFrame) Http2Setting(com.webpieces.http2.api.dto.lowlevel.lib.Http2Setting) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Http2Frame

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame in project webpieces by deanhiller.

the class PushPromiseMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    PushPromiseFrame castFrame = (PushPromiseFrame) frame;
    int originalStreamId = castFrame.getPromisedStreamId();
    int streamId = originalStreamId & 0x7FFFFFFF;
    if (streamId != originalStreamId)
        throw new RuntimeException("your promisedStreamId is too large per spec. frame=" + frame);
    int paddingSize = castFrame.getPadding().getReadableSize();
    byte value = 0x0;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    if (paddingSize > 0)
        value |= 0x8;
    ByteBuffer prelude = bufferPool.nextBuffer(4);
    prelude.putInt(castFrame.getPromisedStreamId());
    prelude.flip();
    DataWrapper headersDW = castFrame.getHeaderFragment();
    DataWrapper finalDW = DATA_GEN.chainDataWrappers(DATA_GEN.wrapByteBuffer(prelude), headersDW);
    DataWrapper payload = PaddingUtil.padDataIfNeeded(finalDW, castFrame.getPadding());
    return super.marshalFrame(frame, value, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PushPromiseFrame(com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame) ByteBuffer(java.nio.ByteBuffer)

Example 4 with Http2Frame

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame in project webpieces by deanhiller.

the class RstStreamMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    RstStreamFrame castFrame = (RstStreamFrame) frame;
    ByteBuffer payload = bufferPool.nextBuffer(4);
    UnsignedData.putUnsignedInt(payload, castFrame.getErrorCode());
    payload.flip();
    DataWrapper dataPayload = DATA_GEN.wrapByteBuffer(payload);
    return super.marshalFrame(frame, (byte) 0, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Http2Frame

use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame in project webpieces by deanhiller.

the class WindowUpdateMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    WindowUpdateFrame castFrame = (WindowUpdateFrame) frame;
    ByteBuffer payload = bufferPool.nextBuffer(4).putInt(castFrame.getWindowSizeIncrement());
    payload.flip();
    DataWrapper dataPayload = DATA_GEN.wrapByteBuffer(payload);
    return super.marshalFrame(frame, (byte) 0, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) WindowUpdateFrame(com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame) ByteBuffer(java.nio.ByteBuffer)

Aggregations

DataWrapper (org.webpieces.data.api.DataWrapper)14 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)11 ByteBuffer (java.nio.ByteBuffer)5 Encoder (com.twitter.hpack.Encoder)4 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)3 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)3 ArrayList (java.util.ArrayList)3 HeaderEncoding (com.webpieces.hpack.impl.HeaderEncoding)2 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)2 ContinuationFrame (com.webpieces.http2.api.dto.lowlevel.ContinuationFrame)2 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)2 PushPromiseFrame (com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame)2 HasHeaderFragment (com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment)2 PriorityDetails (com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails)2 Test (org.junit.Test)2 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)1 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)1 PingFrame (com.webpieces.http2.api.dto.lowlevel.PingFrame)1 PriorityFrame (com.webpieces.http2.api.dto.lowlevel.PriorityFrame)1