Search in sources :

Example 11 with Http2Frame

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

the class TestC4FrameSizeAndHeaders 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 12 with Http2Frame

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

the class HpackParserImpl method createHeadersData.

private DataWrapper createHeadersData(MarshalStateImpl state, Http2Headers headers) {
    long maxFrameSize = state.getMaxRemoteFrameSize();
    Encoder encoder = state.getEncoder();
    List<Http2Frame> headerFrames = encoding.translateToFrames(maxFrameSize, encoder, headers);
    return translate(headerFrames);
}
Also used : Encoder(com.twitter.hpack.Encoder) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Example 13 with Http2Frame

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

the class GoAwayMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
    GoAwayFrame castFrame = (GoAwayFrame) frame;
    long originalStreamId = castFrame.getLastStreamId();
    long streamId = originalStreamId & 0x7FFFFFFF;
    if (streamId != originalStreamId)
        throw new RuntimeException("your lastStreamId is too large per spec. frame=" + frame);
    ByteBuffer prelude = bufferPool.nextBuffer(8);
    UnsignedData.putUnsignedInt(prelude, castFrame.getLastStreamId());
    UnsignedData.putUnsignedInt(prelude, castFrame.getErrorCode());
    prelude.flip();
    DataWrapper debug = DATA_GEN.emptyWrapper();
    if (castFrame.getDebugData() != null)
        debug = castFrame.getDebugData();
    DataWrapper payload = DATA_GEN.chainDataWrappers(DATA_GEN.wrapByteBuffer(prelude), debug);
    return super.marshalFrame(frame, (byte) 0, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)

Example 14 with Http2Frame

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

the class PingMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("PingFrame can never be any other stream id except 0 which is already set");
    PingFrame ping = (PingFrame) frame;
    ByteBuffer payload = bufferPool.nextBuffer(8);
    payload.putLong(ping.getOpaqueData());
    payload.flip();
    DataWrapper dataPayload = DATA_GEN.wrapByteBuffer(payload);
    byte value = 0x0;
    if (ping.isPingResponse())
        value |= 0x1;
    return marshalFrame(frame, value, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PingFrame(com.webpieces.http2.api.dto.lowlevel.PingFrame) ByteBuffer(java.nio.ByteBuffer)

Example 15 with Http2Frame

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

the class PriorityMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    PriorityFrame castFrame = (PriorityFrame) frame;
    PriorityDetails priorityDetails = castFrame.getPriorityDetails();
    DataWrapper payload = marshalPriorityDetails(bufferPool, priorityDetails, frame);
    return super.marshalFrame(frame, (byte) 0, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame)

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