Search in sources :

Example 1 with CancelReason

use of com.webpieces.http2parser.api.dto.CancelReason in project webpieces by deanhiller.

the class Level5AStates method translate.

protected Http2Event translate(Http2SendRecieve sendRecv, Http2Msg payload) {
    Http2PayloadType payloadType;
    if (payload instanceof Http2Headers) {
        Http2Headers head = (Http2Headers) payload;
        if (head.isEndOfStream())
            payloadType = Http2PayloadType.HEADERS_EOS;
        else
            payloadType = Http2PayloadType.HEADERS;
    } else if (payload instanceof DataFrame) {
        DataFrame data = (DataFrame) payload;
        if (data.isEndOfStream())
            payloadType = Http2PayloadType.DATA_EOS;
        else
            payloadType = Http2PayloadType.DATA;
    } else if (payload instanceof Http2Push) {
        payloadType = Http2PayloadType.PUSH_PROMISE;
    } else if (payload instanceof CancelReason) {
        payloadType = Http2PayloadType.RESET_STREAM;
    } else
        throw new IllegalArgumentException("unknown payload type for payload=" + payload);
    return Http2Event.lookup(sendRecv, payloadType);
}
Also used : Http2PayloadType(com.webpieces.http2engine.impl.shared.data.Http2PayloadType) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Push(com.webpieces.hpack.api.dto.Http2Push)

Example 2 with CancelReason

use of com.webpieces.http2parser.api.dto.CancelReason in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_3BadDecompression.

/**
	 *  A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
	 *  
	 */
@Test
public void testSection4_3BadDecompression() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    //has to be 1 since we use 1 in the response
    Assert.assertEquals(1, request.getStreamId());
    String badHeaderFrame = // length
    "00 00 10" + // type
    "01" + // flags (ack)
    "05" + // R + streamid
    "00 00 00 01" + //payload 
    "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
    //endOfStream=false
    mockChannel.writeHexBack(badHeaderFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.COMPRESSION_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:(HEADER_DECODE) Error from hpack library", msg);
    Assert.assertTrue(mockChannel.isClosed());
    List<CancelReason> results = listener1.getRstStreams();
    Assert.assertEquals(1, results.size());
    ShutdownStream failResp = (ShutdownStream) results.get(0);
    Assert.assertEquals(CancelReasonCode.HEADER_DECODE, failResp.getCause().getReasonCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Aggregations

CancelReason (com.webpieces.http2parser.api.dto.CancelReason)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Push (com.webpieces.hpack.api.dto.Http2Push)1 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)1 Http2PayloadType (com.webpieces.http2engine.impl.shared.data.Http2PayloadType)1 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)1 Test (org.junit.Test)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1