Search in sources :

Example 6 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push 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 7 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.

the class Requests method createPush.

public static Http2Push createPush(int streamId) {
    Http2Push push = new Http2Push();
    push.setStreamId(streamId);
    push.setPromisedStreamId(2);
    push.addHeader(new Http2Header(Http2HeaderName.SERVER, "me"));
    return push;
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Push(com.webpieces.hpack.api.dto.Http2Push)

Example 8 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testPushPromise.

@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
    Http2Request request1 = Http2Requests.createRequest(1, true);
    mockChannel.send(request1);
    PassedIn incoming = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming.request);
    Http2Push push = Http2Requests.createPush(request1.getStreamId());
    CompletableFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
    PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
    Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushRecv);
    Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
    pushWriter.processPushResponse(preEmptive);
    Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(preEmptive, preEmptRecv);
    Http2Response response = Http2Requests.createResponse(request1.getStreamId());
    incoming.stream.sendResponse(response);
    Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(response, responseRecv);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) Http2Push(com.webpieces.hpack.api.dto.Http2Push) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 9 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
	 * Receiving any type of frame other than HEADERS, RST_STREAM, or PRIORITY on a
	 * stream in this state MUST be treated as a connection 
	 * error (Section 5.4.1) of type PROTOCOL_ERROR.
	 */
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
    MockPushListener pushListener = new MockPushListener();
    pushListener.setIncomingRespDefault(CompletableFuture.<Void>completedFuture(null));
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    listener1.addReturnValuePush(pushListener);
    Http2Request request = sendRequestToServer(listener1);
    Http2Push push = sendPushFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(push.getPromisedStreamId(), false);
    mockChannel.write(dataFrame);
    //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.assertEquals("ConnectionException: MockHttp2Channel1:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(remote)", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp1 = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp1.getCause().getReasonCode());
    ShutdownStream failResp2 = (ShutdownStream) listener1.getSingleCancelPush();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp2.getCause().getReasonCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Push(com.webpieces.hpack.api.dto.Http2Push) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) MockPushListener(org.webpieces.http2client.mock.MockPushListener) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 10 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.

the class TestC5_1StreamStates method sendPushFromServer.

private Http2Push sendPushFromServer(MockResponseListener listener1, Http2Request request) {
    Http2Push resp1 = Requests.createPush(request.getStreamId());
    mockChannel.write(resp1);
    Http2Push response1 = listener1.getSinglePush();
    Assert.assertEquals(resp1, response1);
    return resp1;
}
Also used : Http2Push(com.webpieces.hpack.api.dto.Http2Push)

Aggregations

Http2Push (com.webpieces.hpack.api.dto.Http2Push)10 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)3 Http2Request (com.webpieces.hpack.api.dto.Http2Request)3 Http2Response (com.webpieces.hpack.api.dto.Http2Response)3 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)3 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3 Test (org.junit.Test)3 DataWrapper (org.webpieces.data.api.DataWrapper)3 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)3 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)2 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2 MockPushListener (org.webpieces.http2client.mock.MockPushListener)2 StreamWriter (com.webpieces.http2engine.api.StreamWriter)1 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)1 Http2PayloadType (com.webpieces.http2engine.impl.shared.data.Http2PayloadType)1 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)1 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)1 PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)1 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)1