Search in sources :

Example 6 with Http2Frame

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

the class Http2ParserImpl method marshal.

// private int getStreamId(DataWrapper data) {
// 
// ByteBuffer streamIdBuffer = bufferPool.nextBuffer(4);
// streamIdBuffer.put(data.readBytesAt(5, 4));
// streamIdBuffer.flip();
// 
// // Ignore the reserved bit
// return streamIdBuffer.getInt() & 0x7FFFFFFF;
// }
@Override
public DataWrapper marshal(Http2Frame frame) {
    Http2FrameType frameType = frame.getFrameType();
    FrameMarshaller marshaller = dtoToMarshaller.get(frameType);
    if (marshaller == null)
        throw new IllegalArgumentException("unknown frame bean=" + frame);
    return marshaller.marshal(frame);
}
Also used : FrameMarshaller(com.webpieces.http2parser.impl.marshallers.FrameMarshaller) Http2FrameType(com.webpieces.http2.api.dto.lowlevel.lib.Http2FrameType)

Example 7 with Http2Frame

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

the class HeadersMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    HeadersFrame castFrame = (HeadersFrame) frame;
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "Headers frame cannot be streamId 0");
    int paddingSize = castFrame.getPadding().getReadableSize();
    byte value = 0x0;
    if (castFrame.isEndOfStream())
        value |= 0x1;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    if (paddingSize > 0)
        value |= 0x8;
    if (castFrame.isPriority())
        value |= 0x20;
    DataWrapper preludeDW;
    PriorityDetails priorityDetails = castFrame.getPriorityDetails();
    if (priorityDetails != null) {
        preludeDW = PriorityMarshaller.marshalPriorityDetails(bufferPool, priorityDetails, frame);
    } else {
        preludeDW = DATA_GEN.emptyWrapper();
    }
    DataWrapper unpadded = DATA_GEN.chainDataWrappers(preludeDW, castFrame.getHeaderFragment());
    DataWrapper payload = PaddingUtil.padDataIfNeeded(unpadded, castFrame.getPadding());
    return super.marshalFrame(frame, value, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) HeadersFrame(com.webpieces.http2.api.dto.lowlevel.HeadersFrame) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 8 with Http2Frame

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

the class HeaderEncoding method translateToFrames.

public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Headers headers) {
    HeadersFrame frame = new HeadersFrame();
    frame.setStreamId(headers.getStreamId());
    frame.setEndOfStream(headers.isEndOfStream());
    frame.setPriorityDetails(headers.getPriorityDetails());
    List<Http2Header> headerList = headers.getHeaders();
    List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
    return headerFrames;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) HeadersFrame(com.webpieces.http2.api.dto.lowlevel.HeadersFrame) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Example 9 with Http2Frame

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

the class HeaderEncoding method translateToFrames.

public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Push p) {
    PushPromiseFrame frame = new PushPromiseFrame();
    frame.setStreamId(p.getStreamId());
    frame.setPromisedStreamId(p.getPromisedStreamId());
    List<Http2Header> headerList = p.getHeaders();
    List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
    return headerFrames;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) PushPromiseFrame(com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Example 10 with Http2Frame

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

the class TestC4FrameSizeAndHeaders method testSection4_3InterleavedFrames.

/**
 * Each header block is processed as a discrete unit. Header blocks
 * MUST be transmitted as a contiguous sequence of frames, with no interleaved
 * frames of any other type or from any other stream. The last frame in a
 * sequence of HEADERS or CONTINUATION frames has the END_HEADERS flag set. The
 * last frame in a sequence of PUSH_PROMISE or CONTINUATION frames has the
 * END_HEADERS flag set. This allows a header block to be logically equivalent to a single frame.
 *
 * Header block fragments can only be sent as the payload of HEADERS, PUSH_PROMISE, or
 * CONTINUATION frames because these frames carry data that can modify the
 * compression context maintained by a receiver. An endpoint receiving
 * HEADERS, PUSH_PROMISE, or CONTINUATION frames needs to reassemble header
 * blocks and perform decompression even if the frames are to be discarded. A receiver
 * MUST terminate the connection with a connection error (Section 5.4.1) of
 * type COMPRESSION_ERROR if it does not decompress a header block.
 */
@Test
public void testSection4_3InterleavedFrames() {
    MockStreamWriter mockStreamWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
    Http2Request request = sendRequestToServer(listener1);
    // has to be 1 since we use 1 in the response
    Assert.assertEquals(1, request.getStreamId());
    List<Http2Frame> frames = createInterleavedFrames();
    // for this test, need interleaved
    Assert.assertTrue(frames.size() >= 3);
    mockChannel.writeFrame(frames.get(0));
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
    mockChannel.writeFrame(frames.get(1));
    ShutdownStream reset = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, reset.getCause().getReasonCode());
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertTrue(msg.contains("Headers/continuations from two different streams per spec cannot be interleaved. "));
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

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